Statalist The Stata Listserver


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

Re: st: data manipulation question


From   "Scott Merryman" <[email protected]>
To   [email protected]
Subject   Re: st: data manipulation question
Date   Tue, 26 Jun 2007 15:54:36 -0500

You could use -levelsof-, -foreach- and -mark- to generate the dummy variables.

For example:

clear
input str3 x
`"IDI"'
`"IDV"'
`"IGI"'
`"IGV"'
end
levelsof x, local(levels)
foreach l of local levels {
	mark `l' if x == "`l'"
}
desc
l


Scott

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?

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