Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Florian Seliger <florian.seliger@gmx.de> |
To | statalist@hsphsun2.harvard.edu |
Subject | st: forvalues + egen rsum with missing variables |
Date | Thu, 6 Jan 2011 18:10:34 -0700 |
Dear Statalist, I'm trying to use the following command on a couple of datasets: egen id_max=max(id) local l=id_max forvalues j=1960(1)2009 { //years forvalues k=1(1)`l' { //number of IDs egen a_`j'=rsum(a_`j'_`k' - a_`j'_`l') } } ******** The problem is that a dataset doesn't contain all years from 1960 to 2009, but only a subset, e.g. 1961, 1985, 1994 etc. In addition, the number of IDs varies (therefore, I need `l' as a maximum) and each year can only be assigned a subset of IDs (they are not assigned in a consistent way). To give an example, I might have the following variables in the dataset: a_1990_63 a_1990_64 a_1990_65 a_1990_66 a_1990_67 a_1990_68 a_1990_69 a_1994_1 a_1994_2 a_1994_3 a_1994_4 a_1994_5 a_1994_6 a_1994_7 a_1994_8 a_1994_9 ... etc. How can I proceed in order to calculate the row sum for each year? I have tried to use "capture", but it didn't work. Thanks a lot, Florian * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/