Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: RE: copy values of matched cases

From   "Patrick Sturgis" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: copy values of matched cases
Date   Tue, 8 Apr 2003 18:58:07 +0100

Many thanks to both Nicks. One other thing which is probably very obvious
but I can't find the answer to: I want to have data files and output in file
rather than alphabetical/numerical order. How does one specify this?


-----Original Message-----
From: [email protected]
[mailto:[email protected]]On Behalf Of Nick Winter
Sent: 08 April 2003 12:58
To: statalist
Subject: st: RE: copy values of matched cases

> I have the following problem:
> I have data on individuals indexed by a unique identifier, SERNO. In
> addition to SERNO, I have a vector of variables Z which are
> measurements
> taken on each individual at time t. Lastly, I have a variable
> SERNO2 which,
> for each case, gives the value of SERNO for a matched case in
> the data set.
> What I wish to do is create a second vector of variables, X,
> which copy the
> values of Z for the case indexed by SERNO2 to each value of SERNO. Any
> suggestions?
> Patrick

I would use -merge-.

	. foreach var of varlist <<Z>> {
	.   rename `var' X_`var'
	. }
	. drop serno2
	. rename serno serno2
	. sort serno2
	. save xdata, replace
	. use <<original dataset>>
	. sort serno2
	. merge serno2 using xdata

Basically, you create a copy of your data that renames the original
variables that you want to merge, and renames the serial number variable
to be the serial number of the matched comparison.  Then when you merge
these data back into the original dataset, you are getting the X_
variables associated with the matched serial number.  Hope this makes

Nick WInter

*   For searches and help try:

*   For searches and help try:

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