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 |
Ari Dothan <ari.dothan@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: Generate a more complex lagged variable |

Date |
Tue, 1 Feb 2011 19:13:34 +0200 |

Tanks much Nick. I will try your suggestions. And thanks for the article suggestion Best On 2/1/11, Nick Cox <njcoxstata@gmail.com> wrote: > You are referring to your code and not showing it to us, so quite what > you did is unclear. > Perhaps you tried something like > > gen H[2] = P[1] > > and as you say Stata doesn't like that. > > It seems that that you have panel data. Setting that aside you would have > > gen H = P[1] in 2 > replace H = a * H[_n-1] + (1 - a) * P[_n-1] in 3/L > > In a panel context that would need to be something like > > bysort firmid (time) : gen H = P[1] if _n == 2 > by firmid : replace H = a * H[_n-1] + (1 - a) * P[_n-1] if _n > 3 > > A basic tutorial on -by:- and subscripts is accessible at > > SJ-2-1 pr0004 . . . . . . . . . . Speaking Stata: How to move step by: > step > . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. > Cox > Q1/02 SJ 2(1):86--102 (no > commands) > explains the use of the by varlist : construct to tackle > a variety of problems with group structure, ranging from > simple calculations for each of several groups to more > advanced manipulations that use the built-in _n and _N > > There would be some gain and no loss in using L.H and L.P after a > -tsset- instead. > Alternatively, in Mata subscripts behave more like what you > (reasonably) seem to expect. > > Nick > > On Tue, Feb 1, 2011 at 4:30 PM, Ari Dothan <ari.dothan@gmail.com> wrote: >> Hi all, >> In the formula H_t=a*H_t-1+(1-a)*P_t-1, P is an existing variable per >> firm/year. >> Assuming that H[2]=P[1], and taking a=0.1: How can I build the column >> of H_t by firm? >> Since it understands [x] as weights, Stata indicates that "weights are >> not allowed", so my problem becomes the specific calculation of each >> observation in the H_t column. > * > * For searches and help try: > * http://www.stata.com/help.cgi?search > * http://www.stata.com/support/statalist/faq > * http://www.ats.ucla.edu/stat/stata/ > -- Ari Dothan * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/statalist/faq * http://www.ats.ucla.edu/stat/stata/

**References**:**st: Generate a more complex lagged variable***From:*Ari Dothan <ari.dothan@gmail.com>

**Re: st: Generate a more complex lagged variable***From:*Nick Cox <njcoxstata@gmail.com>

- Prev by Date:
**st: estimated rates with limits from xtnbreg** - Next by Date:
**re: Re: Re: st: Filtering methods with short time series** - Previous by thread:
**Re: st: Generate a more complex lagged variable** - Next by thread:
**Re: Re: st: Filtering methods with short time series** - Index(es):