--- John A Stefanic <[email protected]> wrote:
> I'm having a lot of trouble combining dummy variables and creating a
> new variable where I count dummy variables.
>
> So, I have a dataset (GSS) with variables SPOUSE1, CHILD1, SPOUSE2,
> CHILD2, SPOUSE3, CHILD3, indicating if person 1, 2, and 3 are a
> spouse or child. In each variable, 1 == Mentioned, 2 == Not
> Mentioned.
>
> Since both SPOUSE1 and CHILD1 are kin, I want to recode them into a
> new variable, KIN1, if either SPOUSE1 or CHILD1 == 1. So I tried:
>
> recode SPOUSE1 SPOUSE2 CHILD1 CHILD2 (2 = 0) (1 = 1) (.a = .a) (.c
> = .c), pre(RE)
>
> Then, I did this:
>
> generate int KIN1 = RESPOUSE1 + RECHILD1
>
> This works fine, I get a new variable KIN1, with values 1 (person is
>
> kin) or 0 (person not kin). But, now I want to make another new
> variable, NUMKIN, indicating the sum of variables KIN1, KIN2, and
> KIN3.
>
> So, I did this:
>
> generate int NUMKIN == KIN1 + KIN2 + KIN3
>
> But, my results exclude a number of cases as missing data. If the
> case is not a "1" for KIN3, it is excluded! Is there something I can
>
> do to change my workflow to make this process easier? How does one
> combine dummy variables in STATA?
You can do that with -egen- and the -rowtotal- expression:
egen int numkin = rowtotal(RESP* RECHI*)
As a matter of personal taste I don't like variables names in capital
letters (too much typing), so one of the first things I do when getting
GSS data is to turn all variable names into lower case:
foreach var of varlist _all {
local lvar = lower("`var'")
rename `var' `lvar'
}
Hope this helps,
Maaren
-----------------------------------------
Maarten L. Buis
Department of Social Research Methodology
Vrije Universiteit Amsterdam
Boelelaan 1081
1081 HV Amsterdam
The Netherlands
visiting address:
Buitenveldertselaan 3 (Metropolitan), room Z434
+31 20 5986715
http://home.fsw.vu.nl/m.buis/
-----------------------------------------
___________________________________________________________
Yahoo! Answers - Got a question? Someone out there knows the answer. Try it
now.
http://uk.answers.yahoo.com/
*
* 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/