Announcement

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

  • Create average variable

    Hi there..

    Im a new user of stata. I need a basic help. I have a panel data. The structure for example

    Region Year Income
    A 2009 4.000
    2010 5.000
    2011 6.000
    B 2009 3.000
    2010 2.500
    2011 7.200
    Help me please to create average variabel of A n B.

    Appreciate anyone's helps

  • #2
    Budi:
    you may want something along the following lines:
    Code:
    use "https://www.stata-press.com/data/r17/nlswork.dta"
    bysort idcode (year): egen wanted=mean(ln_wage)
    list idcode year ln_wage wanted if idcode<=2
           +-------------------------------------+
           | idcode   year    ln_wage     wanted |
           |-------------------------------------|
        1. |      1     70   1.451214   2.040433 |
        2. |      1     71    1.02862   2.040433 |
        3. |      1     72   1.589977   2.040433 |
        4. |      1     73   1.780273   2.040433 |
        5. |      1     75   1.777012   2.040433 |
           |-------------------------------------|
        6. |      1     77   1.778681   2.040433 |
        7. |      1     78   2.493976   2.040433 |
        8. |      1     80   2.551715   2.040433 |
        9. |      1     83   2.420261   2.040433 |
       10. |      1     85   2.614172   2.040433 |
           |-------------------------------------|
       11. |      1     87   2.536374   2.040433 |
       12. |      1     88   2.462927   2.040433 |
       13. |      2     71   1.360348   1.688055 |
       14. |      2     72   1.206198   1.688055 |
       15. |      2     73   1.549883   1.688055 |
           |-------------------------------------|
       16. |      2     75   1.832581   1.688055 |
       17. |      2     77   1.726721   1.688055 |
       18. |      2     78    1.68991   1.688055 |
       19. |      2     80   1.726964   1.688055 |
       20. |      2     82   1.808289   1.688055 |
           |-------------------------------------|
       21. |      2     83   1.863417   1.688055 |
       22. |      2     85   1.789367   1.688055 |
       23. |      2     87    1.84653   1.688055 |
       24. |      2     88   1.856449   1.688055 |
           +-------------------------------------+
    
    .
    Kind regards,
    Carlo
    (Stata 19.0)

    Comment


    • #3
      If your data really are like this

      Code:
      * Example generated by -dataex-. For more info, type help dataex
      clear
      input str12 region double income int year
      "A"   4 2009
      ""    5 2010
      ""    6 2011
      "B"   3 2009
      ""  2.5 2010
      ""  7.2 2011
      end
      Then you'll need to fill in missing values:

      Code:
      replace region = region[_n-1] if missing(region)
      as explained at https://www.stata.com/support/faqs/d...issing-values/

      The mean of ln wage as in @Carlo Lazzaro's helpful answer is the log of the geometric mean, and the geometric mean is often a better summary measure than the mean for incomes.

      Comment

      Working...
      X