Statalist The Stata Listserver

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

st: Re: matching variable values

From   evan roberts <>
Subject   st: Re: matching variable values
Date   Fri, 25 Aug 2006 08:28:10 -0500

Gregor Franz asked how to attach a mother's height to children's records when the mothers were identified by an ID number

sort MomID
save <original-data>, replace
drop MomID
rename ID MomID
rename Height MomHeight
sort MomID
save <temporary-data-file>
use <original-data>, clear
merge MomID using <temporary-data-file>, nokeep

* You will get a message saying "variable MomID does not uniquely identify observations in the master data" because there are multiple children of each mother
* nokeep is necessary so that non-mothers records aren't added to the file attached to no-one.

assert _merge==1 | _merge==3

Dear Statlisters,

I would like to match the values of one variable to the values of
another variable and then create a third variable. Here is the basic setup:

ID      MomID      Height      MomHeight
1         .                  5                  .
2         1                 6                  5
3         .                  6                  .
4         1                  5.5               5   ...

MomHeight is the variable I want to create. It seems straightforward,
but I just can't come up with the right code.

Thank you for any pointers.

Evan Roberts
Minnesota Population Center and Department of History
University of Minnesota
*   For searches and help try:

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