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/