Monday, December 21, 2009

Stata - generating lagged variable for panel data

Say you have a panel dataset with stu_id as the cross-section identifier, and year as the time series identifir. To create a lagged variable for numer:

bysort stu_id (year): gen write_lg=write[_n-1]