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]

From |
Maarten Buis <[email protected]> |

To |
[email protected] |

Subject |
Re: st: Use egen command with time series operator |

Date |
Thu, 28 Nov 2013 10:55:35 +0100 |

On Thu, Nov 28, 2013 at 9:03 AM, Klepsch, Catharina <[email protected]> wrote: > 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. Many of the -egen- commands sort the data internally, thus overwriting your sort prior to calling the -egen- command. This is also true for the -mean()- egen command, as you can see when typing -viewsource _gmean.ado-. This is why the help-file of -egen- contains the warning: "Explicit subscripting (using _N and _n), which is commonly used with generate, should not be used with egen". So you cannot do what you want with the -egen- command. However, if you look at the source code of the mean() egen-command (the -viewsource- command mentioned above), you can see tricks on how to compute this from first principle. Hope this helps, Maarten --------------------------------- Maarten L. Buis WZB Reichpietschufer 50 10785 Berlin Germany http://www.maartenbuis.nl --------------------------------- * * 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/

**Follow-Ups**:**Re: st: Use egen command with time series operator***From:*Nick Cox <[email protected]>

**References**:**st: Use egen command with time series operator***From:*"Klepsch, Catharina" <[email protected]>

- Prev by Date:
**AW: st: Use egen command with time series operator** - Next by Date:
**st: profile.do file** - Previous by thread:
**Re: st: Use egen command with time series operator** - Next by thread:
**Re: st: Use egen command with time series operator** - Index(es):