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: Use egen command with time series operator
From
Prakash Singh <[email protected]>
To
statalist <[email protected]>
Subject
Re: st: Use egen command with time series operator
Date
Thu, 28 Nov 2013 16:49:43 +0530
Catharina, that was typo error, what I meant was
gen lx1=l.x1
egen mean_x1 =mean(lx1), by(ID YEAR)
On Thu, Nov 28, 2013 at 4:15 PM, Klepsch, Catharina <[email protected]> wrote:
> Hi Marteen,
> thank's for your response. I think I found a way to solve that. In fact I used the "tsrevar" command to generate a temporary variable for time-series operated variables. I can then use this tempvar for my egen command. I did it like this:
>
> local meanvars = ""
> tsrevar `xvar'
> display "`r(varlist)'"
> local xvar_new `r(varlist)'
>
> foreach x of varlist `xvar_new' {
> tempvar mean`x'
>
> bys `panelvar': egen `mean`x'' = mean(`x')
> label var `mean`x'' "mean_`x'"
> local meanvars `meanvars' `mean`x''
> }
>
> Catharina
>
> @ Prakash: Thank's for your comment but I agree with Nick, your advice is not useful for my problem.
>
> -----Ursprüngliche Nachricht-----
> Von: [email protected] [mailto:[email protected]] Im Auftrag von Nick Cox
> Gesendet: Donnerstag, 28. November 2013 11:22
> An: [email protected]
> Betreff: Re: st: Use egen command with time series operator
>
> Sorry, but I doubt that this advice from Prakash Singh can be taken at face value.
>
> First off, if you create the lagged variable first, why ask Stata to do the calculation again through the lag operator?
>
> More fundamentally, there is no reason to suppose that a reference to
> l.x1 should not work unless the same values exist elsewhere as a previously created variable. Stata has, to my knowledge, precisely no way of even knowing that, and it makes no sense any way.
>
> I think there is some confusion here, perhaps just in what Prakash typed.
>
> Nick
> [email protected]
>
>
> On 28 November 2013 09:56, Prakash Singh <[email protected]> wrote:
>> Dear Catharina
>> I just checked with dummy data and realized that you need to generate
>> the lagged variable first and then the syntex (egen mean_x1 =
>> mean(l.x1), by(ID YEAR)) will work fine.
>>
>> Prakash
>>
>> On Thu, Nov 28, 2013 at 2:38 PM, Klepsch, Catharina <[email protected]> wrote:
>>> Dear Prakash,
>>>
>>> thank's for the advice, but this doesn't work, too.
>>>
>>> Any other ideas?
>>>
>>> -----Ursprüngliche Nachricht-----
>>> Von: [email protected]
>>> [mailto:[email protected]] Im Auftrag von Prakash
>>> Singh
>>> Gesendet: Donnerstag, 28. November 2013 10:04
>>> An: statalist
>>> Betreff: Re: st: Use egen command with time series operator
>>>
>>> Dear Catharina
>>> try this
>>> egen mean_x1 = mean(l.x1), by(ID YEAR)
>>>
>>> Hope it helps you.
>>>
>>> Prakash
>>>
>>> On Thu, Nov 28, 2013 at 1:33 PM, Klepsch, Catharina <[email protected]> wrote:
>>>> Dear Stata Users,
>>>>
>>>> I was wondering whether it is possible to use the egen command with time series operators.
>>>> For example, I tried to generate the mean value for a lagged variable and used:
>>>>
>>>> sort ID YEAR
>>>> egen mean_x1 = mean(l.x1)
>>>>
>>>> Unfortunately, there occurs an error message which states:
>>>> not sorted r(5)
>>>>
>>>> I'm not quite sure why this happens, because I sorted the data before. Even if I type:
>>>> bys ID YEAR: egen mean_x1 = mean(l.x1)
>>>>
>>>> the same error message occurs.
>>>>
>>>> Any ideas how I can fix that? Please consider that it is not reasonable for my programming to first generate the lag/lead and then generate the mean.
>>>>
>>>> Thank's for any help.
>>>> Catharina
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> *
>>>> * For searches and help try:
>>>> * http://www.stata.com/help.cgi?search
>>>> * http://www.stata.com/support/faqs/resources/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/faqs/resources/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/faqs/resources/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/faqs/resources/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/faqs/resources/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/faqs/resources/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/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/