how to create a time dummy

Reply
Frequent Contributor
Posts: 122

how to create a time dummy

Hi, I have a panel data set with stock ID, month and returns. I would like to generate a time dummy variable that if first month, then q1=1 and other months 0. Is there a quick way to do this? Thanks.

Super User
Super User
Posts: 7,039

Re: how to create a time dummy

data want ;

set have ;

by id month ;

q1 = first.month;

run;

Frequent Contributor
Posts: 122

Re: how to create a time dummy

thanks for the prompt help. I ran the above code, but cannot get what I want. I got q1=1 for all observations. Also, I need to generate many time dummies instead of only one. I have 200 months. Therefore I need 200 dummies, q1 to q200.

Trusted Advisor
Posts: 1,228

Re: how to create a time dummy

Try this.

proc sort data=have;
by stock_id month;
run;

data want;
set have;
by stock_id month;
if first.stock_id then q1=1;
else q1=0;
run;

Frequent Contributor
Posts: 122

Re: how to create a time dummy

No, I don't want to set the first quarter for each stock_id to 1. I have a variable month, which ranges from 1 to 200. I want to create 200 new variables q1 - q200, with q1 = 1 with all observations that have month=1 and 0 otherwise, q200 =1 with all observations that have month=200 and 0 otherwise.

Super User
Posts: 19,778

Re: how to create a time dummy

data want ;

set have ;

array q(200) q1-q200 (200*0);

q(month)=1;

run;

Respected Advisor
Posts: 2,655

Re: how to create a time dummy

proc glmmod data=have outdesign=want;

class time;

model depvar=time;

run;

Steve Denham

Ask a Question
Discussion stats
  • 6 replies
  • 467 views
  • 1 like
  • 5 in conversation