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

Re: st: data manipulation


From   Gary Longton <[email protected]>
To   [email protected]
Subject   Re: st: data manipulation
Date   Tue, 15 Jun 2004 15:25:42 -0700

In addition to Nick's -reshape- solution, here's an alternative approach which uses -bysort- to fill in and drop observations:
The first 2 lines of the -forvalues- loop are just asserting what you imply is true - that there is indeed only one non-missing value for each series variable within country-year combination.

*****************************
forvalues i = 1/3 {
egen notmiss = count(series`i'), by(country year)
assert notmiss == 1
qui bysort country year (series`i'): replace series`i' == series`i'[1]
drop notmiss
}
qui by country year: drop if _n>1
*******************************

- Gary


[email protected] wrote:


Hello, I have what may be a basic question. I have data like this:
country year series1 series2 series3
1 1 1000 . .
1 2 1035 . .
1 1 . 50 .
1 2 . 53 .
1 1 . . 7 1 2 . . 8.5
2 etc


Is there anyway I can basically collapse these so that:
country year series1 series2 series3
1 1 1000 50 7
1 2 1035 53 8.5

for a number of countries?


*
*   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