Hi all, I have the following panel data set with -ID YEAR CITY STATE- variables.
For the purpose of the study, I need do the following:
1. Identify -ID- that does not have -YEAR- 2004.
2. Create an artificial row for this -ID- with -ID YEAR CITY STATE- that copies from whichever is the most recent entry.
3. If there is -ID- with 2004 year entry, skip.
I tried the following construction but I am not sure how to create the row I want:
Any advice/help would be greatly appreciated!
For the purpose of the study, I need do the following:
1. Identify -ID- that does not have -YEAR- 2004.
2. Create an artificial row for this -ID- with -ID YEAR CITY STATE- that copies from whichever is the most recent entry.
3. If there is -ID- with 2004 year entry, skip.
Code:
* Example generated by -dataex-. For more info, type help dataex clear input long id double year str195 city str8 state 1004 2000 "Wood Dale" "IL" 1004 2001 "Wood Dale" "IL" 1004 2002 "Wood Dale" "IL" 1004 2008 "Wood Dale" "IL" 1004 2009 "Wood Dale" "IL" 1004 2010 "Wood Dale" "IL" 1005 2007 "Beaconsfield" "MA" 1005 2008 "Beaconsfield" "MA" 1005 2009 "Beaconsfield" "MA" 1005 2010 "Beaconsfield" "MA" end
Code:
bysort id (year): gen obs = _n local varid id * I think I need a counter variable like ...local i = 1 foreach y of local varid{ * if not have 2004 if max(year) <2004 | min(year) >2004 { * what command should I have here to insert a row with year = 2004 and to keep values in -city- -state-? } }
Comment