--- Molly Lipscomb wrote:
> I have a large dataset that was too big for me to use find
> and replace in Excel for the missing values, so I have many
> variables that contain double periods .. for missing
> observations. I want to change these to missing so that I
> can convert the variables to integers, but I am having
> trouble changing the string values to missing.
> Here is my code right now:
>
> foreach var in $varlist {
> gen `var'1=subinstr(`var', .., , )
> destring `var'1, replace
> drop `var'
> ren `var'1 `var'
> }
Your code can be simplified by using the force option in
-destring-. With this option any non-numeric strings (in your
case double dots) will be turned into a missing value, which
is what you want. So, your code would look something like this:
destring $varlist, replace force
Hope this helps,
Maarten
-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands
visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434
+31 20 5986715
http://home.fsw.vu.nl/m.buis/
-----------------------------------------
*
* 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/