Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.

# Re: st: Code to generate dummy variable from several categorical variables?

 From Nick Cox To statalist@hsphsun2.harvard.edu Subject Re: st: Code to generate dummy variable from several categorical variables? Date Mon, 16 Jan 2012 09:21:27 +0000

```In addition, your own example assigned values 0, 1, 2 to a new
variable. That isn't a dummy (indicator) variable, which can only be 0
or 1 (or missing).

Nick

On Mon, Jan 16, 2012 at 12:55 AM, Nick Cox <njcoxstata@gmail.com> wrote:
> The events
>
> A==0
> B==1
> C==1
>
> are as said not mutually exclusive. So, there seems no cause either
> for surprise or for complaint. If you look at
>
> egen group = group(A B C), label missing
>
> all the distinct cross-combinations will be given distinct values.
>
> . tab group
>
> will then show your complete set-up.
>
> If Stata is not doing what you want, you need to explain what you want
>
> Nick
>
> On Mon, Jan 16, 2012 at 12:41 AM, daniel klein
>
>> I am not really getting what you are trying to do here (and whether it
>> makes sense), since you are not giving any infromation on your
>> variables, but would replacing the line
>>
>> replace abnlX=2 if C==1
>>
>> with
>>
>> replace abnlX=2 if C==1 & mi(abnlX)
>>
>> do what you want?
>>
>>
>> As a side issue, note that this
>>
>> replace abnlX=2 if C==1 & (B==. | B==0 | B==1)
>>
>> can be written as
>>
>> replace abnlX=2 if C==1 & inlist(B, ., 0, 1)
>>
>> See -help inlist()- and -help functions-
>
> Deborah L. Huang
>
>> I'm looking for code to generate a dummy variable from values of
>> several categorical variables which are not mutually exclusive. I've
>> tried to do this using the generate and replace commands but Stata is
>> changing the number of subjects in each dummy category as follows:
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
```