[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
"kelly johnson" <econometrics@hotmail.com> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
st: Looping questions |

Date |
Tue, 09 Aug 2005 08:05:18 -0400 |

Hi,

I can do all of this interactively, but need help writing loops.

(1) Suppose I have a variable, say Var1

How can I write a fundction that calculates the change between successive observations of 10 elements of this variable? Ie. Assume the data is sorted by date, decending. The first observation is (Var1[_n] -Var1[_n+10])/Var[_n+10], the second observation is (Var1[_n+2]-Var1[_n+11])/Var1[_n+11], and so on...Is this an instance where I can use the -rolling- command? If so, how?

(2) Now suppose I want to do this same calculation across say, a hundred variables Var1-Var100. How can I loop across the variables in an efficiant manner?

(3) A more general type of loop: suppose I have 100 variables, and I want to display the mean and std. Deviation of each varible.

Any help will be greatly appreciated. Please be specific regarding the coding!

Thanks,

kj

_________________________________________________________________

Express yourself instantly with MSN Messenger! Download today - it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/

*

* 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/

**Follow-Ups**:**st: Re: Looping questions***From:*"R.E. De Hoyos" <redeho@hotmail.com>

- Prev by Date:
**Re: st: changing the structure of a data set** - Next by Date:
**RE: st: -nl- error message** - Previous by thread:
**st: RE: psmatch2** - Next by thread:
**st: Re: Looping questions** - Index(es):

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