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

RE: st: simple program


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   RE: st: simple program
Date   Tue, 21 Jun 2005 15:52:51 +0100

In addition to Richard's good advice: 

program define growth
	forval i = 1999/2004 {
		local j = `i' + 1 
		gen gro`j' = (y_`j'-y_`i') / y_`i'
	}
end 

or 

program define growth
	forval i = 1999/2004 {
		gen gro`=`i'+1' = (y_`=`i'+1'-y_`i') / y_`i'
	}
end 

Nick 
[email protected] 

Richard Williams
 
> At 09:43 AM 6/21/2005 -0400, Seyda G Wentworth wrote:
> >Hello,
> >I have a long list of exported goods and their annual values 
> (y_1999; 
> >y_2000; y_2001...). I want to compute the growth rate for 
> each of these 
> >products between 1999-2000 called gro2000; between 2000-2001 called 
> >gro2001; and so on till 2003-2004. So I need to create 5 
> variables. I'm 
> >trying to write a simple program of the following sort:
> >
> >program define growth
> >local i=1999
> >while (`i'<=2004) {
> >gen gro`i'+1=(y_`i'+1-y_`i')/y_`i'
> >local i=`i'+1
> >}
> >end
> 
> Instead of all the `i'+1, after the while command insert
> 
> local j = `i' + 1
> 
> and then use `j' instead of `i' + 1

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



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