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]
Re: st: Create a dummy variable meeting 2 conditions
From
William Buchanan <[email protected]>
To
[email protected]
Subject
Re: st: Create a dummy variable meeting 2 conditions
Date
Mon, 24 Feb 2014 15:49:02 -0600
This may get you what you're looking for. The -cond()- function was made for situations like this and makes it much easier to track down problems (if they arise) compared to writing out all of the conditions in different statements explicitly.
g newvar = cond(Var1==1 & inlist(Var2,1,2),1,cond(mi(Var1,Var2),.,0))
HTH,
Billy
On Feb 24, 2014, at 3:43 PM, Li <[email protected]> wrote:
> Dear Statalist members,
>
> I have a question with regard to create a Dummy variable from two
> variables. The coding of the two existing variables are as follows:
>
> Var1: ( 1=smoked over 100 cigars lifetime ; 2 = Not smoked 100
> cigars lifetime; 3= don't know; 99=missing).
> Var2: (1=currently smoke every day; 2=currently smoke some days;
> 3=not smoking; 4=refuse to answer; 99=missing).
>
> The new dummy variable I want to create needs to satisfy two
> conditions: smoked over 100 cigars lifetime and currently smoking
> everyday or some days, i.e.
>
> New variable 1=current smoker (if Var1=1 & Var2=1 or 2);
>
> 0=nonsmoker;
>
> . = Missing, don't know and refuse to
> answer in Var1, Var2).
>
>
> I know it is straightforward to use the "gen" in Stata to meet one
> condition. I would appreciate if anyone shares how to incorporate the
> conditions as above to make a new variable.
>
>
> Thank you very much.
>
>
> Jeff
> *
> * For searches and help try:
> * http://www.stata.com/help.cgi?search
> * http://www.stata.com/support/faqs/resources/statalist-faq/
> * http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/faqs/resources/statalist-faq/
* http://www.ats.ucla.edu/stat/stata/