How to create dummy for certain observations?

Reply
Occasional Contributor
Posts: 6

How to create dummy for certain observations?

Hello all,

Could anyone help me on some codes?

I am working on a panel data, and for certain id-year observations I need to create a dummy as 1. For example, for a firm that has data available from 1990 to 2000, several years of the firms, not necessarily consecutive years, I need to create a dummy, and for the same firm, the rest of the years is 0.

Your timely help will be much appreciated.

Sincerely,

Jason

Super Contributor
Posts: 644

Re: How to create dummy for certain observations?

Here is one approach

/* Get all the firm IDs in one table */

Proc SQL ;

     Create table firms as

          Select distinct ID

     From     have

     Order by ID

     ;

Quit ;

/*     Create a year entry for each firm     */

Data years ;

     Set firms ;

     Do  year =  1990 to 2000 ;

          Output ;

     end ;

Run ;

/*     Merge with original table

     NB Must be sorted by ID and Year

*/

Data want ;

     Merge years

               have (in = Have_it)

               ;

     By     ID      Year ;

     Found = Have_it ;

Run ;

[untested, of course]

Richard

Ask a Question
Discussion stats
  • 1 reply
  • 202 views
  • 0 likes
  • 2 in conversation