Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: data manipulation question


From   "Austin Nichols" <[email protected]>
To   [email protected]
Subject   Re: st: data manipulation question
Date   Tue, 26 Jun 2007 16:56:11 -0400

David Airey <[email protected]>:
-levelsof- -foreach- and -local- are very useful commands--I recommend
getting to know them well (read the help files).

levelsof iso_str, local(vs)
foreach v of local vs {
g byte iso_`v'=(iso_str=="`v') if !mi(iso_str)
}

On 6/26/07, David Airey <[email protected]> wrote:
I have a variable naming question, after encoding.

I used these commands,

encode iso_str, generate(iso)
tab iso, gen(iso_)

"iso_str" was a variable with these levels:

. levels iso_str
`"IDI"' `"IDV"' `"IGI"' `"IGV"' `"INI"' `"INV"' `"ISI"' `"ISV"'
`"MDV"' `"MNI"'
 > `"MNV"' `"MSI"' `"MSV"' `"VDI"' `"VDV"' `"VGI"' `"VGV"' `"VNI"'
`"VNV"' `"VSI"
 > ' `"VSV"'

and so iso has these levels

. levels iso
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

after tab iso, gen(iso_)

I wind up with 1,0 indicator variables for each level of iso, with
useful variable labels. But really I'd like to have indicator
variables named for each level, like "IDI" instead of "iso_1". How do
I do that?


              storage  display     value
variable name   type   format      label      variable label
------------------------------------------------------------------------
-------
iso_str         str3   %9s
iso             long   %8.0g       iso
iso_1           byte   %8.0g                  iso==IDI
iso_2           byte   %8.0g                  iso==IDV
iso_3           byte   %8.0g                  iso==IGI
iso_4           byte   %8.0g                  iso==IGV
iso_5           byte   %8.0g                  iso==INI
iso_6           byte   %8.0g                  iso==INV
iso_7           byte   %8.0g                  iso==ISI
iso_8           byte   %8.0g                  iso==ISV
iso_9           byte   %8.0g                  iso==MDV
iso_10          byte   %8.0g                  iso==MNI
iso_11          byte   %8.0g                  iso==MNV
iso_12          byte   %8.0g                  iso==MSI
iso_13          byte   %8.0g                  iso==MSV
iso_14          byte   %8.0g                  iso==VDI
iso_15          byte   %8.0g                  iso==VDV
iso_16          byte   %8.0g                  iso==VGI
iso_17          byte   %8.0g                  iso==VGV
iso_18          byte   %8.0g                  iso==VNI
iso_19          byte   %8.0g                  iso==VNV
iso_20          byte   %8.0g                  iso==VSI
iso_21          byte   %8.0g                  iso==VSV



--
David C. Airey, Ph.D.
Research Assistant Professor

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

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