Just checking here to see if someone might have an idea for how to easily generate lags and leads for hundreds of variables outside of the context of xtset and tsset. I'm working with data that are not really suitable for xtset or tsset because there are repeated time values even when I've panelized the data. In the example data, I've created a panel ID that includes the department code and the topic, but there are still many repeat values of the year for each panel. Adding year into the panelid doesn't solve the problem, because there are still repeats (i.e., a department could have issued many rules on a particular topic in a particular year). I understand that it would be possible to manually generate lags and leads for any given variable, but since I'm going to be doing so much of it (there are far more than just bills and eos in the data), I wonder if there's a way to get around the repeated time values problem in xtset or tsset.
Code:
* Example generated by -dataex-. To install: ssc install dataex clear input int year byte indep int bills byte eos long(topic deptcode2) float panelid 2008 0 19 0 1 5 5 2005 0 4 0 8 10 115 2006 0 24 0 19 14 284 1996 0 49 0 41 11 611 2007 0 68 0 19 14 284 2007 0 172 0 17 11 251 2008 0 348 0 21 12 312 1996 0 56 0 21 9 309 2010 0 11 0 13 7 187 2016 0 6 0 36 4 529 1999 0 8 0 32 11 476 2001 0 32 0 14 4 199 2000 0 3 0 22 8 323 2009 0 77 0 25 2 362 2010 0 13 0 16 14 239 2011 0 34 0 24 10 355 2013 0 12 0 10 5 140 2009 0 903 0 21 11 311 2006 0 12 0 10 14 149 2018 0 . . 22 14 329 2005 0 49 1 31 9 459 2007 0 83 0 14 3 198 2010 0 26 0 18 6 261 2018 0 . . 30 14 449 2008 0 23 0 40 11 596 2002 0 17 2 25 14 374 2005 0 58 1 6 11 86 2006 0 0 0 30 2 437 1999 0 66 2 6 14 89 1998 0 10 0 13 14 194 2006 0 12 0 18 14 269 2007 0 33 0 33 12 492 2018 0 . . 31 14 464 2007 0 68 0 19 14 284 2013 0 71 1 37 14 554 2008 0 37 0 19 14 284 2000 0 14 0 10 9 144 2009 0 10 0 13 9 189 2005 0 134 0 17 5 245 2009 0 77 0 25 6 366 2012 0 31 0 7 8 98 2002 0 1 0 8 9 114 2015 0 4 0 23 14 344 2002 0 57 2 20 11 296 2007 0 79 1 11 14 164 2008 0 37 0 19 14 284 2012 0 12 0 27 2 392 2018 0 . . 34 5 500 2016 0 4 0 27 3 393 2011 0 138 0 20 14 299 2005 0 22 0 40 11 596 2014 0 1 0 32 13 478 2008 0 37 0 19 14 284 2005 0 44 0 37 1 541 2008 0 37 0 19 14 284 2013 0 23 1 5 5 65 2001 0 43 0 7 9 99 2002 0 20 0 24 11 356 2009 0 68 0 19 14 284 2009 0 48 0 3 8 38 1998 0 34 0 31 2 452 2008 0 27 0 36 13 538 2003 0 71 0 41 11 611 2012 0 2090 0 21 8 308 2009 0 81 0 38 8 563 2013 0 6 0 28 11 416 2008 0 32 0 27 11 401 1998 0 9 0 28 11 416 2014 0 70 0 20 3 288 2004 0 22 0 31 12 462 2018 0 . . 24 14 359 2010 0 79 0 17 1 241 2009 0 68 0 19 14 284 2009 0 68 0 19 14 284 2009 0 68 0 19 14 284 2013 0 54 1 7 5 95 2018 0 . . 25 14 374 2009 0 54 0 33 11 491 2017 0 . 0 13 14 194 1997 0 4 0 23 8 338 2007 0 79 1 11 12 162 2004 0 15 0 24 5 350 2010 0 15 0 19 14 284 2008 0 13 0 5 9 69 2010 0 15 0 19 14 284 2006 0 3 0 8 8 113 2011 0 20 0 15 4 214 2002 0 10 0 32 11 476 2007 0 25 0 25 3 363 2018 0 . . 12 5 170 2018 0 . . 34 5 500 2006 0 6 0 9 13 133 2003 0 77 0 27 9 399 1996 0 33 0 20 6 291 2013 0 33 1 2 1 16 2010 0 15 0 19 14 284 2010 0 15 0 19 14 284 2010 0 26 0 41 14 614 2002 0 39 0 23 6 336 2003 0 71 0 41 12 612 end label values topic topic label def topic 1 "Agriculture", modify label def topic 2 "Air Pollution", modify label def topic 3 "Aviation", modify label def topic 5 "Chemicals", modify label def topic 6 "Civil Service", modify label def topic 7 "Consumer Finance", modify label def topic 8 "Contracting", modify label def topic 9 "Disability", modify label def topic 10 "Education", modify label def topic 11 "Energy Efficiency", modify label def topic 12 "Exports", modify label def topic 13 "Fisheries", modify label def topic 14 "Food & Drug", modify label def topic 15 "Food Safety", modify label def topic 16 "Hazardous Waste", modify label def topic 17 "Health Insurance", modify label def topic 18 "Highway Safety", modify label def topic 19 "Hospitals", modify label def topic 20 "Immigration", modify label def topic 21 "Imports", modify label def topic 22 "Intergovernmental", modify label def topic 23 "Land Management", modify label def topic 24 "Long-Term Care", modify label def topic 25 "Maritime", modify label def topic 27 "Medicare", modify label def topic 28 "Planning", modify label def topic 30 "Public Housing", modify label def topic 31 "Records", modify label def topic 32 "Rural Development", modify label def topic 33 "Securities", modify label def topic 34 "Small Business 1", modify label def topic 36 "Species 1", modify label def topic 37 "Species 2", modify label def topic 38 "Species 3", modify label def topic 40 "Training", modify label def topic 41 "Water Resources", modify label values deptcode2 deptcode2 label def deptcode2 1 "1000", modify label def deptcode2 2 "1100", modify label def deptcode2 3 "1200", modify label def deptcode2 4 "1500", modify label def deptcode2 5 "1600", modify label def deptcode2 6 "1800", modify label def deptcode2 7 "1900", modify label def deptcode2 8 "2000", modify label def deptcode2 9 "2100", modify label def deptcode2 10 "2500", modify label def deptcode2 11 "500", modify label def deptcode2 12 "600", modify label def deptcode2 13 "700", modify label def deptcode2 14 "900", modify label values panelid panelid label def panelid 5 "Agriculture 1600", modify label def panelid 16 "Air Pollution 1000", modify label def panelid 38 "Aviation 2000", modify label def panelid 65 "Chemicals 1600", modify label def panelid 69 "Chemicals 2100", modify label def panelid 86 "Civil Service 500", modify label def panelid 89 "Civil Service 900", modify label def panelid 95 "Consumer Finance 1600", modify label def panelid 98 "Consumer Finance 2000", modify label def panelid 99 "Consumer Finance 2100", modify label def panelid 113 "Contracting 2000", modify label def panelid 114 "Contracting 2100", modify label def panelid 115 "Contracting 2500", modify label def panelid 133 "Disability 700", modify label def panelid 140 "Education 1600", modify label def panelid 144 "Education 2100", modify label def panelid 149 "Education 900", modify label def panelid 162 "Energy Efficiency 600", modify label def panelid 164 "Energy Efficiency 900", modify label def panelid 170 "Exports 1600", modify label def panelid 187 "Fisheries 1900", modify label def panelid 189 "Fisheries 2100", modify label def panelid 194 "Fisheries 900", modify label def panelid 198 "Food & Drug 1200", modify label def panelid 199 "Food & Drug 1500", modify label def panelid 214 "Food Safety 1500", modify label def panelid 239 "Hazardous Waste 900", modify label def panelid 241 "Health Insurance 1000", modify label def panelid 245 "Health Insurance 1600", modify label def panelid 251 "Health Insurance 500", modify label def panelid 261 "Highway Safety 1800", modify label def panelid 269 "Highway Safety 900", modify label def panelid 284 "Hospitals 900", modify label def panelid 288 "Immigration 1200", modify label def panelid 291 "Immigration 1800", modify label def panelid 296 "Immigration 500", modify label def panelid 299 "Immigration 900", modify label def panelid 308 "Imports 2000", modify label def panelid 309 "Imports 2100", modify label def panelid 311 "Imports 500", modify label def panelid 312 "Imports 600", modify label def panelid 323 "Intergovernmental 2000", modify label def panelid 329 "Intergovernmental 900", modify label def panelid 336 "Land Management 1800", modify label def panelid 338 "Land Management 2000", modify label def panelid 344 "Land Management 900", modify label def panelid 350 "Long-Term Care 1600", modify label def panelid 355 "Long-Term Care 2500", modify label def panelid 356 "Long-Term Care 500", modify label def panelid 359 "Long-Term Care 900", modify label def panelid 362 "Maritime 1100", modify label def panelid 363 "Maritime 1200", modify label def panelid 366 "Maritime 1800", modify label def panelid 374 "Maritime 900", modify label def panelid 392 "Medicare 1100", modify label def panelid 393 "Medicare 1200", modify label def panelid 399 "Medicare 2100", modify label def panelid 401 "Medicare 500", modify label def panelid 416 "Planning 500", modify label def panelid 437 "Public Housing 1100", modify label def panelid 449 "Public Housing 900", modify label def panelid 452 "Records 1100", modify label def panelid 459 "Records 2100", modify label def panelid 462 "Records 600", modify label def panelid 464 "Records 900", modify label def panelid 476 "Rural Development 500", modify label def panelid 478 "Rural Development 700", modify label def panelid 491 "Securities 500", modify label def panelid 492 "Securities 600", modify label def panelid 500 "Small Business 1 1600", modify label def panelid 529 "Species 1 1500", modify label def panelid 538 "Species 1 700", modify label def panelid 541 "Species 2 1000", modify label def panelid 554 "Species 2 900", modify label def panelid 563 "Species 3 2000", modify label def panelid 596 "Training 500", modify label def panelid 611 "Water Resources 500", modify label def panelid 612 "Water Resources 600", modify label def panelid 614 "Water Resources 900", modify
Comment