Announcement

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

  • Generating missing data

    Hi!

    i have a panel of data with a single misuration for every months over 8 years. For some months i have no data available, so i would fill my empty cells with an average value obtained from the values of the same months in the other years. Is there some command that let me able to do this?

    Thank you

  • #2
    Emanuele:
    see: https://www.statalist.org/forums/for...using-mipolate.
    As you will find in this thread, the approach you have in mind is far from being methodologically sound.
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      Sure, although whether this is a good idea is the major question. You don't give a data example, so here is some token code based on made up data.


      Code:
      * Example generated by -dataex-. To install: ssc install dataex
      clear
      input float(month year mdate y)
       1 2011 612  1
       2 2011 613  2
       3 2011 614  3
       4 2011 615  4
       5 2011 616  5
       6 2011 617  6
       7 2011 618  7
       8 2011 619  8
       9 2011 620  9
      10 2011 621 10
      11 2011 622 11
      12 2011 623 12
       1 2012 624 13
       2 2012 625  .
       3 2012 626 15
       4 2012 627 16
       5 2012 628 17
       6 2012 629 18
       7 2012 630 19
       8 2012 631 20
       9 2012 632 21
      10 2012 633 22
      11 2012 634 23
      12 2012 635 24
      end
      format %tm mdate
      
      egen mean = mean(y), by(month)
      
      replace y = mean if missing(y)
      
      list
      
           +------------------------------------+
           | month   year     mdate    y   mean |
           |------------------------------------|
        1. |     1   2011    2011m1    1      7 |
        2. |     2   2011    2011m2    2      2 |
        3. |     3   2011    2011m3    3      9 |
        4. |     4   2011    2011m4    4     10 |
        5. |     5   2011    2011m5    5     11 |
           |------------------------------------|
        6. |     6   2011    2011m6    6     12 |
        7. |     7   2011    2011m7    7     13 |
        8. |     8   2011    2011m8    8     14 |
        9. |     9   2011    2011m9    9     15 |
       10. |    10   2011   2011m10   10     16 |
           |------------------------------------|
       11. |    11   2011   2011m11   11     17 |
       12. |    12   2011   2011m12   12     18 |
       13. |     1   2012    2012m1   13      7 |
       14. |     2   2012    2012m2    2      2 |
       15. |     3   2012    2012m3   15      9 |
           |------------------------------------|
       16. |     4   2012    2012m4   16     10 |
       17. |     5   2012    2012m5   17     11 |
       18. |     6   2012    2012m6   18     12 |
       19. |     7   2012    2012m7   19     13 |
       20. |     8   2012    2012m8   20     14 |
           |------------------------------------|
       21. |     9   2012    2012m9   21     15 |
       22. |    10   2012   2012m10   22     16 |
       23. |    11   2012   2012m11   23     17 |
       24. |    12   2012   2012m12   24     18 |
           +------------------------------------+
      I think you'd usually get a better answer by interpolation. This method will be very poor unless trend is absent and seasonality exactly the same over a series of months.

      Comment

      Working...
      X