Statalist


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

Re: st: Problem creating multiple loops


From   "Carlos Eduardo Hern�ndez Castillo" <[email protected]>
To   [email protected]
Subject   Re: st: Problem creating multiple loops
Date   Fri, 13 Jun 2008 12:45:29 -0500

Hi. I reckon this should work:

forvalues byear = 1993(1)2002 {
	forvalues cont = 1(1) 4 {
		local year=`byear'+`cont'
		gen var1_`cont' = ln(((var1_`year'-var1_`byear')/var1_`byear')+1) if
year==`byear'
	}
}

On Fri, Jun 13, 2008 at 12:29 PM, Hugh Colaco <[email protected]> wrote:
> Hi,
>
> I realize that my earlier post a couple of days ago was not very
> clear. So, here is another try. I need a more efficient code than the
> one below. I tried various combinations of -local-, -foreach- and
> -forval-, but am unable to get it right.
>
>
>       gen var1_1 = ln(((var1_1994-var1_1993)/var1_1993)+1) if year==1993;
>
>       gen var1_2 = ln(((var1_1995-var1_1993)/var1_1993)+1) if year==1993;
>
>       gen var1_3 = ln(((var1_1996-var1_1993)/var1_1993)+1) if year==1993;
>
>       gen var1_4 = ln(((var1_1997-var1_1993)/var1_1993)+1) if year==1993;
>
>
>       replace var1_1 = ln(((var1_1995-var1_1994)/var1_1994)+1) if year==1994;
>
>       replace var1_2 = ln(((var1_1996-var1_1994)/var1_1994)+1) if year==1994;
>
>       replace var1_3 = ln(((var1_1997-var1_1994)/var1_1994)+1) if year==1994;
>
>       replace var1_4 = ln(((var1_1998-var1_1994)/var1_1994)+1) if year==1994;
>
>
>       ............
>
>       ............
>
>       ............
>
>       replace var1_1 = ln(((var1_2003-var1_2002)/var1_2002)+1) if year==2002;
>
>       replace var1_2 = ln(((var1_2004-var1_2002)/var1_2002)+1) if year==2002;
>
>       replace var1_3 = ln(((var1_2005-var1_2002)/var1_2002)+1) if year==2002;
>
>       replace var1_4 = ln(((var1_2006-var1_2002)/var1_2002)+1) if year==2002;
>
>
> Thanks in advance,
> --
> Hugh
> *
> *   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/
>
*
*   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