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 |
Anders Alexandersson <andersalex@gmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: to write _n in [./.] form |

Date |
Fri, 25 Feb 2011 17:15:19 -0500 |

Ajjee, I would create a -touse- variable to simplify repeating code. One example is at http://www.stata.com/statalist/archive/2010-11/msg00089.html If the calculations are much easier in wide form instead, then I would consider temporarily reshaping to wide for the calculations. Anders Alexandersson andersalex@gmail.com On Fri, Feb 25, 2011, ajjee <ajjee1@yahoo.com> wrote: > I have to calculate a variable in this way > > gen awc_4=1 if awc[_n]==1 & awc[_n+1]!=1 & awc[_n+2]!=1 & awc[_n+3]!=1 & > awc[_n+4]!=1 > > and on basis of the above variable, generate a new variable of average > > gen rgg3avgf=( rgg[_n]+ rgg[_n+1]+ rgg[_n+2])/3 if awc_4[_n-1]==1 > > Is there a way to write the above commands in short form ( like, _n/_n+3) as > for other variables I've to include more terms in calculation of awc_3y and > also for higher term in averages. * * 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/

**Follow-Ups**:**st: Stata SE 11.1 memory problem***From:*figengunes@bilkent.edu.tr

**References**:**st: to write _n in [./.] form***From:*ajjee <ajjee1@yahoo.com>

- Prev by Date:
**RE: st: RE: questions about Fixed Effect models** - Next by Date:
**st: Stata SE 11.1 memory problem** - Previous by thread:
**st: to write _n in [./.] form** - Next by thread:
**st: Stata SE 11.1 memory problem** - Index(es):