Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Adding additional observations in a panel data

    Hello,

    Excuse my title if it does a poor job describing my problem.

    My data currently looks like this (although with 59400 obs and 66 variables) and the panel variable is mquint.


    Code:
    * Example generated by -dataex-. To install: ssc install dataex
    clear
    input float(mquint monthly return)
    1 270      0
    1 270 -.0154
    2 270      0
    2 270   .016
    3 270 -.0333
    3 270 -.0043
    4 270  .0242
    4 270 -.0194
    5 270 -.0051
    5 270 -.0184
    end
    format %tm monthly
    I need help in making a code which allows me to add additional observations equal to how many observations each value of mquint has. These new observations will be the return of mquint = 1 minus return of mquint = 5.

    I tried doing this by reshape wide, but I was not able to make any code that was efficient or I was sure was working.

    Thanks in advance, and excuse my poor english (second language)

  • #2
    Perhaps your subsequent question
    https://www.statalist.org/forums/for...r-reshape-wide
    was a step on the way to addressing this problem, and if so, perhaps the answer posted there provides some direction.

    With that said, the description of this problem leaves me with questions about your data. You show two observations for each value of mquint, but in your text you suggest there may be a different number. And your data provides no way of distinguishing between the two observations for each value of mquint: if you had to sort your data, how would you put it back in order?

    Comment


    • #3
      Hello,

      Yes, the other thread was a step in adressing this problem, and I believe I will be able to solve it now.

      And regarding my dataset, I forgot to mention I do have another identifier which makes me able to distinguish between the observations.

      Thank you for your help.

      Comment

      Working...
      X