Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: st: forvalues + egen rsum with missing variables
From
Florian Seliger <[email protected]>
To
[email protected]
Subject
Re: st: forvalues + egen rsum with missing variables
Date
Fri, 7 Jan 2011 01:42:35 -0700
You are absolutely right.
Thank you.
Am 06.01.2011 um 10:23 schrieb Nick Cox:
> -rsum()- is an old and undocumented synonym for what is now called
> -rowtotal()-. But it still works.
>
> I have not really tried to understand this, as I think your posting
> implies one major piece of advice.
>
> It looks as if you need to -reshape long-. After that, not only this
> but many other tasks of data management and statistical analysis will
> be much easier and this messy problem will just reduce to one
> involving -by:-.
>
> Nick
>
> On Fri, Jan 7, 2011 at 1:10 AM, Florian Seliger <[email protected]> wrote:
>
>> 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.
>
> *
> * 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/
*
* 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/