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: How to check if observation of a particular variable value exists? If not, create that observation.
From
Ran Gu <[email protected]>
To
[email protected]
Subject
st: How to check if observation of a particular variable value exists? If not, create that observation.
Date
Tue, 29 May 2012 10:09:40 +0100
Dear Statalisters:
Good day. I hope you can help me with the following question.
Suppose I have a data with 2 variables, say A and B, both with values
1 and 2. The data are sorted by A and B. Then there should be 4
records: (A=1 B=1) (A=1 B=2) (A=2 B=1) (A=2 B=2)
Suppose I don't know whether the 4 observations are all exist or not.
How could I check that in a do file?
Then, If a record is missing, say (A=1 B=1), I would like to create it.
for example:
forvalues i = 1/2 {
forvalues j = 1/2 {
if obs with A == `i' and B == `j' is missing {
local new = _N+1
set obs `new'
replace A == `i' if _n==`new'
replace B == `j' if _n==`new'
}
}
}
--
All the best,
Ran
*
* 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/