Statistics Help @ Talk Stats Forum - Stata
http://www.talkstats.com/
Stata usage and programming, Stata helpenMon, 24 Jul 2017 14:22:12 GMTvBulletin60http://www.talkstats.com/images/misc/rss.pngStatistics Help @ Talk Stats Forum - Stata
http://www.talkstats.com/
Tidy way to generate a new variable based on information from many other variables?
http://www.talkstats.com/showthread.php/69907-Tidy-way-to-generate-a-new-variable-based-on-information-from-many-other-variables?goto=newpost
Sat, 22 Jul 2017 19:56:49 GMTHi All,
Suppose I have a set of variables {x1, x2, x3, x4, x5, x6, x7, x8...}. I would like to generate a new variable that takes a value of 1 if...Hi All,

Suppose I have a set of variables {x1, x2, x3, x4, x5, x6, x7, x8...}. I would like to generate a new variable that takes a value of 1 if x1=1 or if x2 =1 or if x3=1 etc...

I have been doing this crudely by:

gen newvar = 0
replace newvar = 1 if x1==1 | x2==1 | x2==1 etc...

I presume there is a tidier way of doing this? Any help is much appreciated.
]]>StataNickmpcohttp://www.talkstats.com/showthread.php/69907-Tidy-way-to-generate-a-new-variable-based-on-information-from-many-other-variables