Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: RE: assigning same number to slightly different string var.


From   Nick Cox <[email protected]>
To   "'[email protected]'" <[email protected]>
Subject   st: RE: assigning same number to slightly different string var.
Date   Tue, 1 Nov 2011 11:02:22 +0000

You want a new  variable, which could be constructed like this 

gen newvar = . 
replace newvar = 1 if strpos(myvar, "500") 
replace newvar = 2 if strpos(myvar, "Dax") 
... 

-if strpos(,)- is equivalent to -if strpos(,) > 0-. 

tab myvar if missing(newvar) 

will tell you what you missed. 

You will also want to define value labels and assign them. 

Nick 
[email protected] 

Philip Hantschk

i have a set of data containing names of indices, like S&P 500, Dax 30 etc. I want to assign numbers to the indices, so that S&P 500=1, Dax 30=2 etc. The problem is, that the in the observations, S&P 500 has different ways of writing, e.g. Standard and Poor's 500, S&P 500, S&P 500 Index, etc. 

My question is, is there a way to assign numbers automatically, like tell Stata to give every observation that contains "500" the "1".


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index