Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, is already up and running.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Lag operators on panel data inside -bysort-

From   Richard Herron <>
Subject   st: Lag operators on panel data inside -bysort-
Date   Mon, 29 Oct 2012 11:02:49 -0400

I would like to use lag operators on panel data inside a -bysort-
command, but I get the -not sorted- error. For example, using the
following data,

webuse grunfeld, clear
xtset company year

* generate quantiles with -xtile- from -egenmore- (SSC)
egen invest_q = xtile(invest), by(year)

neither of the following two lines work.

bysort invest_q: regress mvalue l.invest
bysort invest_q (company year): regress mvalue invest[_n-1]

I thought -xtset-'s effects were persistent, but the error makes
sense. Is there an elegant solution? (It would be nice to be able to
use lag operators on the fly.) Or is the best option to generate
lagged variables as follows.

generate linvest = l.invest

*   For searches and help try:

© Copyright 1996–2016 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index