Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: Need help with working across variables


From   Michael Stewart <michaelstewartresearch@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: Need help with working across variables
Date   Sat, 9 Feb 2013 23:56:34 -0500

HI ,
Here is my data format and my question:
id	var1	var2	var3	var4
1	1	1	1	.
2	1	1	1	1
3	1	2	1	.
4	2	2	2	2
5	1	1	1	1
6	1	2	.	.
7	2	1	2	.

I am trying to generate a new variable x =1 if all non missings values
for the variables(per observation) are equal to 1 and x =2 if all non
missings values for the variables(per observation) are equal to 2. I
tried to do foreach loop like

gen x=0
foreach x in var1 var2 var3 var4{
replace x=1 if `x'=1
}
but it doesnt seem to do the trick

I am specifically interested in to change x =1 if all nonmissign
values for an observation are equal to one
For example: I would like to replace x=1 for id=1 but not for id 3
Similarly, I would like to replace x=2 if all nom missing values for
an observation are equal to two.

-- 
Thank you ,
Yours Sincerely,
Mike.
*
*   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/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index