Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: re: What to do about multiple observations for one individual in one same period in a panel


From   Kit Baum <[email protected]>
To   [email protected]
Subject   st: re: What to do about multiple observations for one individual in one same period in a panel
Date   Sun, 19 Jul 2009 15:02:33 -0400

<>
Martin (yes, I doublechecked, this was Martin!) suggested

Aggregate the two levels via -egen, group()-:

I applaud Martin's efforts in answering questions, but a couple of issues with this one: (1) example code would be more useful if it runs when pasted in the do- file editor, which this does not (2) this solution does not really address the question, as it does not answer how the questioner can end up with panel data. This code modifies Martin's suggestions to implement my earlier suggestions:
-----------------------
 clear*
input country:mylabel /*
 */ str10 date, auto
Argentina   "1990:1"
Argentina   "1990:1"
Argentina   "1990:1"
Argentina   "1990:2"
Argentina   "1990:3"
Argentina   "1990:4"
Argentina   "1990:4"
Argentina   "1990:4"
Argentina   "1990:4"
Argentina   "1991:1"
Argentina   "1991:1"
Argentina   "2008:3"
Argentina   "2008:4"
Argentina   "2008:4"
Brazil      "1990:1"
Brazil      "1990:2"
Brazil      "1990:2"
Brazil      "1990:3"
Brazil      "1990:3"
Brazil      "1990:3"
Brazil      "1990:3"
end

gen date2 = quarterly(date, "YQ")
format date2 %tq
drop date

// some fake data on amounts, yields, tenors
gen amount = runiform()*1000 + 100
gen yield = runiform()*5 + 4
gen tenor = runiform()*2 + 8
l, sepby(country date2)

// get total issued by country-year
bys country date2: gen tot = sum(amount)
// get weights for each issue within country-year
bys country date2: g weight = amount / tot[_N]
// calc weighted average yield and tenor
bys country date2: g wtyield = weight * yield
bys country date2: g wttenor = weight * tenor
collapse (count) nissue=amount (sum) amount ///
    wtyield wttenor, by(country date2)
tsset country date2
l, sepby(country)
------------------------------------------
Kit
Kit Baum   |   Boston College Economics & DIW Berlin   |   http://ideas.repec.org/e/pba1.html
An Introduction to Stata Programming | http://www.stata-press.com/books/isp.html
   An Introduction to Modern Econometrics Using Stata  |   http://www.stata-press.com/books/imeus.html



*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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