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

st: RE: Lagged variable question

From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: Lagged variable question
Date   Tue, 30 Jul 2002 14:35:34 +0100

[email protected]
> I am relatively new to Stata. I read the manuals but could
> not figure out
> the following on my own. Please excuse if this turns out to
> be a very silly question.
> I have panel data in the long format, and declared them
> appropriately:
> -tsset subject period-
> In some descriptive analyses, I want to make the following
> count statement
> (assume that g is the name of the variable of interest):
> -count if period==20 & L0.g==0 & L1.g==0 & L2.g==0 .... and
> so forth, until
> L15.g==0-
> I am looking for an abbreviation meaning "lag 0 to lag 15
> of variable g are
> all 0", because I will need this kind of statement
> frequently. Typing
> L(0/15).g does not work.
> Any suggestions would be very much appreciated. In case I overlooked
> something in the docus, please point me to the documentation.

Here is one way to do it:

Let's suppose the suspect innocent until declared
guilty, that is, we believe that all lagged values are zero
until we find one which isn't:

gen allzero = 1

forval i = 0/15 {
	replace allzero = allzero * (L`i'.g == 0)

The quantity

L`i'.g is in turn L0.g L1.g ... L14.g L15.g


(L`i'.g == 0) is 1 or 0 depending on whether the lagged
value is 0 or not.

You can also do it with the logical operator "&". The result
is naturally the same.

Some other approaches break down because they won't
accept the time series operators.

For more on true and false in Stata, see

For more on any/all problems, see

[email protected]

*   For searches and help try:

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