Statalist The Stata Listserver


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: Replace missing values for pairs of variables


From   "Maarten Buis" <M.Buis@fsw.vu.nl>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: Replace missing values for pairs of variables
Date   Wed, 10 May 2006 17:22:16 +0200

----Hugh wrote:
> I have pairs of variables (i.e. p1 q1, p2 q2, etc. The final pair is
> pfinal and qfinal). All I want is that when either p`i' or q`i' has a
> blank, it takes the value of 0 while the other retains its value. When
> both p and q are blank, I dont want anything to be changed.

Hugh:
It is easier if the final pair also adheres to the format pnumber, qnumber.
Than the code looks like this:

forvalues 1 = 1/3 {
	replace p`i' = 0 if p`i' == . & q`i' != .
	replace q`i' = 0 if q`i' == . & p`i' != .
}

Otherwise it looks like this:

local stub "1 2 final"
foreach i of local stub {
replace p`i' = 0 if p`i' == . & q`i' != .
	replace q`i' = 0 if q`i' == . & p`i' != .
}

HTH,
Maarten



*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



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