Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: -for- and its fortes


From   Ronan Conroy <[email protected]>
To   [email protected]
Subject   st: -for- and its fortes
Date   Wed, 24 Jul 2002 09:51:39 +0100

on 23/7/02 4:46 PM, Nick Cox at [email protected] 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 

This command 
- encodes a variable, using a predefined mapping contained in the value
label `b1',
- 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 protected])
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:
*   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