I am having trouble coding for up to 5 lagged and lead variables, the code I am using doesn't accurately take into account missing waves.
This is being used on stata 15.0.
I am using panel data from the british household panel survey and the meaning for my variables are:
pid =ID number of the individual, wave = time, M0 = if an individual migrated in that wave.
The code that i Used was:
sort pid wave
gen lag1 = M0[_n-1] if wave==wave[_n-1]+1
gen lag2 = M0[_n-2] if wave==wave[_n-1]+1
gen lag3 = M0[_n-3] if wave==wave[_n-1]+1
gen lag4 = M0[_n-4] if wave==wave[_n-1]+1
gen lag5 = M0[_n-5] if wave==wave[_n-1]+1
gen lead1 = M0[_n+1] if wave==wave[_n-1]+1
gen lead2 = M0[_n+2] if wave==wave[_n-1]+1
gen lead3 = M0[_n+3] if wave==wave[_n-1]+1
gen lead4 = M0[_n+4] if wave==wave[_n-1]+1
gen lead5 = M0[_n+5] if wave==wave[_n-1]+1
gen lead6 = M0[_n+6] if wave==wave[_n-1]+1
I was wondering if there is a way to take into account unbalanced panel and data for lagged and lead variables, i though "if wave==wave[_n-1]+1" would solve for this issue?
this was the result that I got:
It doesn't accurately take into account the missing wave ( wave 11, line 8->9),
thank you for your time
This is being used on stata 15.0.
I am using panel data from the british household panel survey and the meaning for my variables are:
pid =ID number of the individual, wave = time, M0 = if an individual migrated in that wave.
The code that i Used was:
sort pid wave
gen lag1 = M0[_n-1] if wave==wave[_n-1]+1
gen lag2 = M0[_n-2] if wave==wave[_n-1]+1
gen lag3 = M0[_n-3] if wave==wave[_n-1]+1
gen lag4 = M0[_n-4] if wave==wave[_n-1]+1
gen lag5 = M0[_n-5] if wave==wave[_n-1]+1
gen lead1 = M0[_n+1] if wave==wave[_n-1]+1
gen lead2 = M0[_n+2] if wave==wave[_n-1]+1
gen lead3 = M0[_n+3] if wave==wave[_n-1]+1
gen lead4 = M0[_n+4] if wave==wave[_n-1]+1
gen lead5 = M0[_n+5] if wave==wave[_n-1]+1
gen lead6 = M0[_n+6] if wave==wave[_n-1]+1
I was wondering if there is a way to take into account unbalanced panel and data for lagged and lead variables, i though "if wave==wave[_n-1]+1" would solve for this issue?
this was the result that I got:
It doesn't accurately take into account the missing wave ( wave 11, line 8->9),
thank you for your time
Comment