Announcement

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

  • Mean of 5 obs. in Panel Dataset

    Hello,

    I have a Panel data and I've been searching for a command allowing me to compute an average of 5 values of my "growth" variable of each country (please see blow)

    The average values will be in a new column of course.


    Thank you!

    Click image for larger version

Name:	Screenshot 2024-02-10 at 13.20.22.png
Views:	1
Size:	733.3 KB
ID:	1742772
    Last edited by Anass Wajib; 10 Feb 2024, 06:32.

  • #2
    Anass: please follow the FAQ when posting. Thanks.
    That said, you may find what follow helpful:
    Code:
    . use "https://www.stata-press.com/data/r18/nlswork.dta"
    (National Longitudinal Survey of Young Women, 14-24 years old in 1968)
    
    . bysort idcode (year): egen wanted=mean(ln_wage) if year<=75
    
    
    . list wanted if idcode==1
    
           +----------+
           |   wanted |
           |----------|
        1. | 1.525419 |
        2. | 1.525419 |
        3. | 1.525419 |
        4. | 1.525419 |
        5. | 1.525419 |
           |----------|
        6. |        . |
        7. |        . |
        8. |        . |
        9. |        . |
       10. |        . |
           |----------|
       11. |        . |
       12. |        . |
           +----------+
    
    .
    Kind regards,
    Carlo
    (StataNow 18.5)

    Comment


    • #3
      Carlo Lazzaro Apologies for the late response, I made sure to fully look into your link and understand it.

      It worked! Thank you immensely. One last question please, since the timeline in your example starts at year 70, the command works perfect but my timeline has many missing observations (please see picture above) before the sought out years. It there a command that tells STATA to start from year X and end with year Y. Something similar as such 1986>=mean<=1990.

      Thank you again.

      Comment


      • #4
        Stata has lots of functionality here. Check out tssmooth (official), rangestat (SSC) and commands like


        Code:
        egen wanted8690 = mean(cond(inrange(year, 1986, 1990), growth, .))
        On the last, see Section 9 of https://journals.sagepub.com/doi/pdf...867X1101100210

        The rest of the paper may be helpful.

        Comment


        • #5
          Nick Cox Thank you very much for your assistance

          Comment

          Working...
          X