Dear all,
Hi, I have a dataset with T=52 annual observations. I want to create dummy variables for all years. I can do this by
tab year, gen(year)
For the sake of example, let me take T=4. The command generates tab1 (1 if year==1, 0 otherwise), tab2 (1 if year==2, 0 otherwise), tab3 (1 if year==3, 0 otherwise), tab4 (1 if year==4, 0 otherwise).
In addition to these plain dummies, I want to generate interaction dummies with, say, independent variable x. I can do this in a brute force manner by
gen x1=x*tab1
gen x2=x*tab2
gen x3=x*tab3
gen x4=x*tab4
My first question is, is there a more efficient way of generating interaction dummies x1, x2, x3?
I can then run a regression like
reg y tab2 tab3 tab4 x x2 x3 x4
My second question is, is there a more efficient way of writing out this regression? For example,
reg y tab2-4 x x2-4
or something along that line.
I'd be really grateful for any and all advice. Thank you very much in advance!
Best,
John
Hi, I have a dataset with T=52 annual observations. I want to create dummy variables for all years. I can do this by
tab year, gen(year)
For the sake of example, let me take T=4. The command generates tab1 (1 if year==1, 0 otherwise), tab2 (1 if year==2, 0 otherwise), tab3 (1 if year==3, 0 otherwise), tab4 (1 if year==4, 0 otherwise).
In addition to these plain dummies, I want to generate interaction dummies with, say, independent variable x. I can do this in a brute force manner by
gen x1=x*tab1
gen x2=x*tab2
gen x3=x*tab3
gen x4=x*tab4
My first question is, is there a more efficient way of generating interaction dummies x1, x2, x3?
I can then run a regression like
reg y tab2 tab3 tab4 x x2 x3 x4
My second question is, is there a more efficient way of writing out this regression? For example,
reg y tab2-4 x x2-4
or something along that line.
I'd be really grateful for any and all advice. Thank you very much in advance!
Best,
John
Comment