Statalist


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

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


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

Make that "Ma*rt?n"


HTH
Martin _______________________ ----- Original Message ----- From: "Nick Cox" <[email protected]>
To: <[email protected]>
Sent: Sunday, January 18, 2009 7:15 PM
Subject: st: RE: i and i-1 in forvalues command


Mart*n quite rightly both drew attention to `=`i' - 1'. If that seems a little tricky, just spell it out:
forvalues i = 1/5 {
local j = `i' - 1 replace kat = `i' if hour > kat`j' & hour <= kat`i'
}

Nick [email protected]
Florian Wakolbinger

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?


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