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: Generate new var - sum of multiple var
From
Maarten Buis <[email protected]>
To
[email protected]
Subject
Re: st: Generate new var - sum of multiple var
Date
Tue, 23 Aug 2011 17:25:28 +0200
On Tue, Aug 23, 2011 at 5:20 PM, Jonathan Grondin wrote:
> I have a 4 questions survey(q1, q2, q3, q4). Each one of the 4
> questions can either be answered by 1 or by 0.
> I'd like to generate a new variable(new_var) holding, for every
> participants, the number of question they answered with the value 1.
> In other word, the sum of the 4 questions.
>
> new_var would then hold values from 0 to 4
gen newvar = q1 + q2 + q3 + q4
or
egen newvar = rowtotal(q*)
There are subtle differences between these solutions in the way they
handle missing values, see -help egen-.
Hope this helps,
Maarten
--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany
http://www.maartenbuis.nl
--------------------------
*
* 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/