Hi,
I am trying to create a variable using a lead operator for data that is a monthly panel. The variable I am trying to get the lead for is measured at the yearly level though. To get the first and second leads, I am using the following code:
Is this the best/most efficient approach to create this operator?
I am trying to create a variable using a lead operator for data that is a monthly panel. The variable I am trying to get the lead for is measured at the yearly level though. To get the first and second leads, I am using the following code:
Code:
xtset id mdate set more off foreach var of varlist var1 var2 { g first`var' = `var'==0 & F12.`var'==1 if F12.`var'!=. g second`var' = `var'==0 & F24.`var'==0 & F24.`var'==1 if F24.`var'!=. & F24.`var'!=. }
Comment