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 on April 23, and its replacement, is already up and running.

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

st: RE: Creating variable in Stata

From   "Nick Cox" <>
To   <>
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. 


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:
        (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


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==.


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:

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