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

st: RE: string values in a gen command


From   "Daniel Mueller" <[email protected]>
To   <[email protected]>
Subject   st: RE: string values in a gen command
Date   Tue, 5 Aug 2003 21:56:14 +0200

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


. gen newvar=""

. replace newvar="whatever" if oldvar1==1 & oldvar2==1

Daniel



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