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

st: Re: merging variables within groups


From   Joseph Coveney <[email protected]>
To   Statalist <[email protected]>
Subject   st: Re: merging variables within groups
Date   Tue, 27 May 2003 22:56:30 +0900

In my response to Gayatri Koolwal's posting, the do-file replaced the values of the third 
variable with the desired values from the second variable.  I didn't notice that Gayatri 
wanted to generate a new, fourth, variable containing the values and not to replace the 
values of the existing third variable.  The slight modification shown in do-file below will 
accomplish this.

Joseph Coveney

--------------------------------------------------------------------------------

* next few lines are just inputing the dataset
clear
input str4 not_for_use str1 obs_no str1 id1 str1 id2
hhd1	a	n	o
hhd1	b	o	

hhd2	c	p	r
hhd2	d	q	
hhd2	e	r	

hhd3	f	s	o
hhd3	g	o	
end
* the action starts here
sort obs_no
generate str1 id4 = ""
generate byte id3 = id2!=""
replace id3 = sum(id3)
bysort id3: replace id4 = obs_no[_N] if _n == 1
exit

--------------------------------------------------------------------------------


*
*   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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index