Hello,

I am now trying to repeat the same difference-in-differences analysis with changing treatment variables.
The basic idea is:
the control group is always January and I would like to compare January to each month from February to September.
(While the comparison period is 2019 vs. 2020.)

For example,
Code:
recode year (2019=0) (2020=1)
recode month (1=0) (2=1) (3/9=.), gen(month2)
diff log_income, t(month2) p(year)
diff log_income, t(month2) p(year) cov(sex i.edu age) robust

recode year (2019=0) (2020=1)
recode month (1=0) (3=1) (2=.) (4/9=.), gen(month3)
diff log_income, t(month3) p(year)
diff log_income, t(month3) p(year) cov(sex i.edu age) robust

recode year (2019=0) (2020=1)
recode month (1=0) (4=1) (2/3=.) (5/9=.), gen(month4)
diff log_income, t(month4) p(year)
diff log_income, t(month4) p(year) cov(sex i.edu age) robust
Of course, I can copy and paste the same code:
Code:
diff log_income, t(month4) p(year)
diff log_income, t(month4) p(year) cov(sex i.edu age) robust
for every time I recode the treatment month. But there are two problems.
(1) If I would like to add more covariables, I need to add them repeatedly.
(2) I am also planning to do the same analysis by changing treatment and control months (such as Jan-Feb vs. May-June), then I would need to copy and paste so many more times with all the available combinations of comparison.

Thus, I wonder if there is any way in STATA to make my work easier.
I guess something like foreach would help, but I have never used it and it seems always difficult to use for me.

I have been given so much supports from Statlist so far and I really appreciate this site and all the people helping each other here.
I look forward to your reply!

Best,

Jiwan