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]
st: RE: Creating variable in Stata
From 
 
"Nick Cox" <[email protected]> 
To 
 
<[email protected]> 
Subject 
 
st: RE: Creating variable in Stata 
Date 
 
Fri, 19 Mar 2010 18:33:47 -0000 
First, your attempts won't work because here variable4/variable81 and
variable4-variable81 mean what the arithmetic operators / and - imply
and do _not_ provide ways of including all the variables in question. 
-egen-'s -rownonmiss()- counts nonmissing values rowwise. If the answer
is 0, all values are missing in an observation. 
Note also that system missing . is just the simplest kind of missing
value for numeric variables. Testing whether values equal . will not
capture any use of .a to .z and it will fail with string variables, for
which missing means the empty string "". But the -egen- function above
and its sibling -rowmiss()- are aware of all that. 
Given 
egen rownonmiss = rownonmiss(<varlist>) 
then an indicator for "all missing" is given by 
gen byte allmissing = rownonmissing == 0 
A tutorial on working row-wise is available in 
SJ-9-1  pr0046  . . . . . . . . . . . . . . . . . . .  Speaking Stata:
Rowwise
        (help rowsort, rowranks if installed) . . . . . . . . . . .  N.
J. Cox
        Q1/09   SJ 9(1):137--157
        shows how to exploit functions, egen functions, and Mata
        for working rowwise; rowsort and rowranks are introduced
Nick 
[email protected] 
Shellenberg, Kristen
I'd like to create a variable that indicates whether several variables
in the dataset (77 actually) are all coded as missing (.) for a
respondent.  I've tried the following with no luck... 
gen info_C=0
replace info_C=1 if variable4/variable81==.
and 
gen info_C=0
replace info_C=1 if variable4-variable81==.
Can anyone tell me how to generate a variable that will tell me if a
whole set of variables were coded as missing without writing out replace
info_C=1 if variable1==.& variable2==. and so on for all 77 variables?
*
*   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/