Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Re: i and i-1 in forvalues command


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: Re: i and i-1 in forvalues command
Date   Sat, 17 Jan 2009 17:42:19 +0100

sysuse auto, clear
forv i=1/5{
di in red mpg[`i']
di in red mpg[`=`i'-1']
}

HTH
Martin _______________________ ----- Original Message ----- From: "Florian Wakolbinger" <[email protected]>
To: <[email protected]>
Sent: Saturday, January 17, 2009 5:37 PM
Subject: st: i and i-1 in forvalues command


Dear all,

I want to categorize the subjects in my dataset according to the number of hours they work. I define say 5 kategories with kat0, kat1, kat2,..., kat5 being the highest number of hours in each category.

Then I categorize using

gen kat = .

forvalues i = 1/5 {
  replace kat = `i' if hour > kat`i-1' & hour <= kat`i'
  }

the problem is I apparently cant write i-1 between ` and '

does anybody know how I can access i-1 while the loop is in state i?

thanks for your help!
best, Florian
*
*   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/

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



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