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

st: Looping questions

From   "kelly johnson" <>
Subject   st: Looping questions
Date   Tue, 09 Aug 2005 08:05:18 -0400


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!



Express yourself instantly with MSN Messenger! Download today - it's FREE!

* For searches and help try:

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