On 12/12/06, Nick Cox <[email protected]> wrote:
Other advice is that you won't get in Stata with
this data structure. Consider a -reshape long-.
Nick
[email protected]
Thank you for that advice Nick!
Ironically, I started out by using reshape wide, to get around merging issues.
So (as I possibly should have done from the beginning...) I'll
describe my entire problem, as best as I can:
I have three files:
-pregoutcome.dta containing information about births. Each birth is
one observation. Relevant variables are individid (of mother), round
(that the birth was registered) and date (of the birth)
-residency.dta containing information about the various residencies an
individual has had, with each residency episode being one observation.
Relevant variables are locationid, individid (of the individual the
residency record is related to), sdate (start of residency) and edate
(end of residency)
-observation.dta, containing information about the observation (visit)
times of each residency location, with each visit being one
observation. Relevant variables are date (of the observation) round
(that the observation was made) and locationid (of the residency
location that was observed)
Now, I want to attach the observation data of the residency where the
mother was "observed" in the round previous to the round in which the
birth was registered.
The goal is to see whether or not she was registered as pregnant
before giving birth.
Now, In the best of all possible worlds, all individid's and
locationid's would be unique in each file, and I could do:
use pregoutcome.dta
sort individid
merge individid using residency.dta
sort locationid
merge locationid using observation.dta
drop if observe_round~=birth_round-1
, and be finished. However, each individid can occur more than once in
pregoutcome,and can have moved several times, and thus have several
location records in residency.dta.
Since merge doesn't expand records (in a manner I can understand) when
both master and using data set contain non-unique identifiers, I was
making the identifiers unique, and then tried to extract the data.
If you are saying that this path is unworkable, I'm at a loss.
Hopefully there's some alternative to merge that could work, but I
don't know about such a command.
best,
Gustaf
*
* 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/