Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: RE: Lags (verification)


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: Lags (verification)
Date   Mon, 11 Nov 2002 17:31:52 -0000

Maureen Paul
> 
> Hi, I would like to regard the years as the time variable, 
> I think. It is a panel, so I have tsset as follows (wave is 
> the year variable): tsset pid wave.
> I have a variable called, say, VAR and I would like to 
> create a new variable LAGVAR, which contains its lags 
> taking into consideration that there is a gap of 2 years 
> between each waves and in one case the gap is 3 years. 
> Could you suggest how I could change what I have done to 
> achieve this purpose? Would numbering the waves 1 to 5 
> still be appropriate?  Thanks. I include what I did before again.
> 
> tsset pid wave
> ge LAGVAR1=VAR-L2.VAR
>            foreach i of numlist 2000 { replace LAGVAR1=. if 
>  wave==`i' }
> ge LAGVAR2=LAGVAR-L3.LAGVAR
>           foreach i of numlist 1991 1993 1995 1997 { replace 
>  LAGVAR2=. if wave==`i' }
>  ge LAGVAR=LAGVAR1 if LAGVAR1~=.
>  replace LAGVAR=LAGVAR2 if LAGVAR2~=.
> 

Whether numbering the waves 1 to 5 
is sensible is a substantive or perhaps 
even a scientific question: absent 
any information on what these data are, 
that is a judgement for you. 

The consequence of choosing years 
as the time variable is universal missings. 
Consider these fabricated data: 

. l

            id       year  whatever
  1.         1       1991         2
  2.         1       1993         7
  3.         1       1995         6
  4.         1       1997         7
  5.         1       2000         7
  6.         2       1991         2
  7.         2       1993         7
  8.         2       1995         1
  9.         2       1997         6
 10.         2       2000         9

. tsset id year
       panel variable:  id, 1 to 2
        time variable:  year, 1991 to 2000, but with gaps

. gen lagwhatever = L.whatever
(10 missing values generated)

. l

            id       year  whatever  lagwhat~r
  1.         1       1991         2          .
  2.         1       1993         7          .
  3.         1       1995         6          .
  4.         1       1997         7          .
  5.         1       2000         7          .
  6.         2       1991         2          .
  7.         2       1993         7          .
  8.         2       1995         1          .
  9.         2       1997         6          .
 10.         2       2000         9          .

This is an ineluctable consequence of
the gaps.  

However, should you 

. egen pseudotime = group(wave) 
. tsset id pseudotime 

then lagged variables should be mostly non-missing. 
That amounts to ignoring the difference
between gaps of 2 and gaps of 3 years. 

Nick 
[email protected] 

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index