[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
st: -for- and its fortes
on 23/7/02 4:46 PM, Nick Cox at firstname.lastname@example.org wrote:
> On the whole, I think nested problems are more common in
> (my) Stata practice.
By contrast, -for- problems are commoner in my practice. The ability of
-for- to execute multiple commands means that I occasionally use it to
process lists containing a single item!
Consider these real examples:
. for var b101_estwom b104_estboynf b105_estgincest
b109_estprosecution:encode X, gen(X_) label(b1) \ move X_ X \ drop X \
rename X_ X
- encodes a variable, using a predefined mapping contained in the value
- generates a new variable with the same name but with an underscore added,
- moves the new variable to be where the old variable is,
- drops the old variable,
- renames the new variable so that it has the original variable name.
Because you can refer to the variable as X, it means that this bit of code
is faster to write for a single variable than spelling out the name in full.
. for var b101_estwom :encode X, gen(X_) label(b1) \ move X_ X \ drop X \
rename X_ X
Is a lot faster and neater than
. encode b101_estwom , gen(b101_estwom_) lab(b1)
. move b101_estwom_ b101_estwom
. drop b101_estwom
. rename b101_estwom_ b101_estwom
Ronan M Conroy (email@example.com)
Lecturer in Biostatistics
Royal College of Surgeons
Dublin 2, Ireland
+353 1 402 2431 (fax 2329)
And now, Mr President, how about the global alliance against climate change?
* For searches and help try: