Bookmark and Share

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: creating lagged variables


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: creating lagged variables
Date   Sat, 10 Aug 2013 19:14:28 +0100

What do you mean by "the usual lag command"?

What didn't work for you? You don't give either the precise syntax you
used or the exact consequences of using it. Please see the Statalist
FAQ for advice on asking better questions.

Various guesses suggest that you need to know this.

1. Stata has no -lag- command. It does support a lag operator L (see
-help varlist-?)

2. The -egen- function you need is not -mean()- but -rowmean()-. This
follows because you want to average across variables here, not
observations.

3. -rowmean()- does not support time-series operators, so you need to
create the corresponding lagged variables first.

This example may help indicate technique.

webuse grunfeld
tsset company year
forval j = 1/3 {
       gen mvalue`j' = L`j'.mvalue
}
egen mean_lagged = rowmean(mvalue?)

Note that -by:- is unnecessary here as the L. operator automatically
respects panel structure.

In fact your syntax

by country year :

might just divide your data into groups with one observation each.

I didn't understand all the description of your data. If you don't
have successive years in your data, you might need to use different
time identifiers for the observations in each panel. Gaps between
years are likely to create just lots of missings otherwise.

Nick
[email protected]


On 10 August 2013 18:13, Sule <[email protected]> wrote:

> I have a multilevel dataset where I have individual survey responses  collected at different time points( waves but different years), and country level data.Some countries are in all waves, some are only in some of them.
> I would like to generate a lagged independent variable. I would like to take an average of its values at t-1, t-2 and t-3 where t denotes a year when there was a survey study for a particular country.
> I don't know what command to use in stata for  'at' or 'when' .
> .by country year: egen meanlaggedx=3D mean(x(at time-1) x(at time-2) x(at time-3)) is pretty much what I am trying to do, but to no avail. How do I specify a variable a certain time point?
>
> For some reason the usual lag command does not respond in my dataset.
> I appreciate any help or suggestion.
*
*   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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index