Statalist


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

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


From   "Martin Weiss" <martin.weiss1@gmx.de>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: AW: re: What to do about multiple observations for one individual in one same period in a panel
Date   Sun, 19 Jul 2009 22:04:56 +0200

<> 


" example code would be more useful if it runs when pasted in the do- 
file editor, which this does not"



I have pasted my own code into my do-file editor, hit the "Do" button, and
it runs w/o a hitch. Here`s the output:


  +----------------------------------+
  |   country    date2   unit   bond |
  |----------------------------------|
  | Argentina   1990q1      1      1 |
  | Argentina   1990q1      1      2 |
  | Argentina   1990q1      1      3 |
  |----------------------------------|
  | Argentina   1990q2      2      1 |
  |----------------------------------|
  | Argentina   1990q3      3      1 |
  |----------------------------------|
  | Argentina   1990q4      4      1 |
  | Argentina   1990q4      4      2 |
  | Argentina   1990q4      4      3 |
  | Argentina   1990q4      4      4 |
  |----------------------------------|
  | Argentina   1991q1      5      1 |
  | Argentina   1991q1      5      2 |
  |----------------------------------|
  | Argentina   2008q3      6      1 |
  |----------------------------------|
  | Argentina   2008q4      7      1 |
  | Argentina   2008q4      7      2 |
  |----------------------------------|
  |    Brazil   1990q1      8      1 |
  |----------------------------------|
  |    Brazil   1990q2      9      1 |
  |    Brazil   1990q2      9      2 |
  |----------------------------------|
  |    Brazil   1990q3     10      1 |
  |    Brazil   1990q3     10      2 |
  |    Brazil   1990q3     10      3 |
  |    Brazil   1990q3     10      4 |
  +----------------------------------+


Where did yours stop? I have used such code in replies for months, and there
has never been a complaint of this nature. I do have a hunch, though, that
it could have something to do with your email program.


I am of course glad to see improvements with regard to content, such as you
added here. 


HTH
Martin


-----Ursprüngliche Nachricht-----
Von: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] Im Auftrag von Kit Baum
Gesendet: Sonntag, 19. Juli 2009 21:03
An: statalist@hsphsun2.harvard.edu
Betreff: st: re: What to do about multiple observations for one individual
in one same period in a panel

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


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