Hello stata community,

I have a panel set of law effective data for state by year , and I need to create a one year lagged variable for that law panel variable since it takes a year to see the effect of law.

out of the mentioned 2 commands which one I should follow :

sort state year
by state: gen law_lag = law[_n-1] or ############## sort state
by state: gen law_lag = law[_n-1] if year==year[_n-1]+1