Hi,
I would like to create multiple dummy variables(BC_dum_"") (14 in total) for 5 periods before, the day of and 8 periods after the event if another dummy variable (BC) equals 1 using a for loop on a firm level (firmid--> permno). The dummy variable BC equals 1 if a law was passed in that year. So if a law was passed in 1989 then I want to create a dummy variable=1 in 1984 (period -5), and so on. The code I currently have is:
Which does work, however e.g. for BC_dum_-5 is set =1 for multiple years and not just for 1984 as in the example above. I have also tried it with:
But with that I get the error message
I feel (or hope) that I am not far off doing it correctly, so any help would be appreciated!
Thanks
I would like to create multiple dummy variables(BC_dum_"") (14 in total) for 5 periods before, the day of and 8 periods after the event if another dummy variable (BC) equals 1 using a for loop on a firm level (firmid--> permno). The dummy variable BC equals 1 if a law was passed in that year. So if a law was passed in 1989 then I want to create a dummy variable=1 in 1984 (period -5), and so on. The code I currently have is:
Code:
gen BC_dum_6=1 if BC==1 forvalues i = 1/5{ gen BC_dum_-`i' = 0 bysort permno: replace BC_dum_`i' = 1 if BC[_n-`i']==BC & BC==1 } forvalues i = 7/14{ gen BC_dum_`i' = 0 bysort permno: replace BC_dum_`i' = 1 if BC[_n+`i']==BC & BC==1 }
Code:
gen BC_dum_6=1 if BC==1 forvalues i = 1/5{ gen BC_dum_`i' = 0 bysort permno: replace BC_dum_-`i' = 1 if BC[_n-`i']==BC & BC==1 } forvalues i = 7/14{ gen BC_dum_`i' = 0 bysort permno: replace BC_dum_`i' = 1 if BC[_n+`i']==BC & BC==1 }
invalid syntax
r(198);
r(198);
Thanks
Comment