Statalist The Stata Listserver


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

st: RE: Dummy Variable From a String


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: Dummy Variable From a String
Date   Mon, 20 Nov 2006 18:07:32 -0000

You don't give a definition of the dummy variable 
you want. But 

tab myvar, gen(myvar) 

will generate a set of dummies regardless of 
whether -myvar- is string or numeric. 

And if -myvar- is string, 

gen is4c = myvar == "4c" 

is 1 or 0 depending on whether the equality on the RHS 
is true or false. And so on. 

Not only do you not want to -destring-, -destring- 
could at best map some of your values to missing,
so it is hard to see how it could be any use even
for any other purpose. 

Nick 
[email protected] 

[email protected]
 
> I need to create a dummy variable from a string variable that 
> contains 
> both numbers and letters.  The string variable is a number sometimes 
> followed by the letter 'c'.  For example:
> 
> 1
> 2
> 3
> 4c
> 5c
> 6c
> 
> I need to create a dummy variable from this variable without 
> destringing 
> it.  Any ideas?

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