[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]
Re: st: string values in a gen command
To Robert Bozick:
gen newvar = "z1" if oldvar1 == 1 & oldvar2 == 1
Properly, this is...
gen str2 newvar = "z1" if oldvar1 == 1 & oldvar2 == 1
but with Stata 8, the -str2- is optional.
Note that this does it all in one step; no need to first load newvar with
null strings. But if you prefer, you can do...
gen newvar = ""
replace newvar = "z1" if oldvar1 == 1 & oldvar2 == 1
I hope this is what you were looking for.
At 11:44 AM 8/5/2003 -0400, you wrote:
I am having a simple problem. I am trying to create a string variable
based upon a number of conditions.
The gist of the code is this:
gen newvar = .
replace newvar = 1 if oldvar1 == 1 & oldvar2 == 1
This produces 16 cases where newvar = 1, which is exactly correct.
However, I don't want newvar to = 1, I want it to be a string character
z1. If oldvar == 1 & oldvar2 == 1, I want newvar to take the string value
of "z1" --- How do I go about doing this? I know this is really simple,
so thanks in advance!
Institute for Policy Studies
Johns Hopkins University
* For searches and help try: