Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Re: creating a newvar with sequential values from a bunch of stringvariables


From   Suzy <scott_788@wowway.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: Re: creating a newvar with sequential values from a bunch of stringvariables
Date   Sun, 26 Jun 2005 10:17:49 -0400

I'm sorry for confusing the issue by using newvar=44 as an example. I was just showing how many separate categories I would need to create by doing it manually versus if I could just create a single category newvar=1 and code something like this... replace newvar=1 if var1 =="71600/71699" | var2=="71600/71699" | var3=="71600/71699" | var4=="71600/71699"
(0 changes made).

I tried destring before and for some reason, had lost a tremendous amount of observations within the string variables. I'll revisit that again on some practice dataset! Thank you for the optional coding - I'll try that to see if it works.
Thanks for the help!
Suzy

At 01:35 PM 6/25/2005 -0400, Suzy wrote:

replace newvar=1 if var1 =="71600/71699" | var2=="71600/71699" | var3=="71600/71699" | var4=="71600/71699"
(0 changes made)

But no changes occurred, which is impossible.
I'm not sure if this would work but it seems like you need to rework your quote marks, e.g.

replace newvar=1 if var1 =="71600"/"71699" etc.

Even so, I'm not clear on how your 2 pieces of code are supposed to be equivalent, i.e. the first snippet sets newvar to 44 and the 2nd snippet sets it to 1.

Also I wonder if your life would be easier if you used the -destring- command to create numeric versions of these string variables; see the help for destring.

-------------------------------------------
Richard Williams, Notre Dame Dept of Sociology
OFFICE: (574)631-6668, (574)631-6463
FAX: (574)288-4373
HOME: (574)289-5227
EMAIL: Richard.A.Williams.5@ND.Edu
WWW (personal): http://www.nd.edu/~rwilliam <http://www.nd.edu/%7Erwilliam>
WWW (department): http://www.nd.edu/~soc <http://www.nd.edu/%7Esoc>


Suzy wrote:


Dear members:

I created a new variable (newvar) that is supposed to be a collection of sequential values from different string variables. The values that are included in the new variable go from 71600 to 71699. I've been doing it manually for hours- replacing value after value. see example for value # 71623:

replace newvar=44 if var1 =="71623" | var2=="71623" | var33=="71623" | var4=="71623"
(10 real changes made)


I tried to do it this way - see example:

replace newvar=1 if var1 =="71600/71699" | var2=="71600/71699" | var3=="71600/71699" | var4=="71600/71699"
(0 changes made)

But no changes occurred, which is impossible.

I'm hoping there is a simple and quick syntax for what I'd like to do. Ideally if newvar =1 with all the values from 71600 t0 71699 located from the existing variables (1-4) included in newvar - then that would be less painful than what I've been doing.

Any simple solution?? explicit code is appreciated!!
Thanks,
Suzy



*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index