Announcement

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

  • Panel Data

    Hi, I am working with panel data and want to create a dummy variable based on the median of each cross section for the entire sample and also at each time period. How do I do that?

  • #2
    Below is an example. Not sure if what you were asking. For example, the value of wanted in 2011 is 2 which is the median of 2, 1, 2, 0, 4 (the 2011 values of id 1-5).

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input float(id year v)
    1 2011 2
    1 2012 1
    1 2013 4
    2 2011 1
    2 2012 5
    2 2013 1
    3 2011 2
    3 2012 2
    3 2013 3
    4 2011 0
    4 2012 2
    4 2013 0
    5 2011 4
    5 2012 4
    5 2013 3
    end
    
    . bys year: egen wanted = median(v)
    
    . sort id year
    
    . list
    
         +------------------------+
         | id   year   v   wanted |
         |------------------------|
      1. |  1   2011   2        2 |
      2. |  1   2012   1        2 |
      3. |  1   2013   4        3 |
      4. |  2   2011   1        2 |
      5. |  2   2012   5        2 |
         |------------------------|
      6. |  2   2013   1        3 |
      7. |  3   2011   2        2 |
      8. |  3   2012   2        2 |
      9. |  3   2013   3        3 |
     10. |  4   2011   0        2 |
         |------------------------|
     11. |  4   2012   2        2 |
     12. |  4   2013   0        3 |
     13. |  5   2011   4        2 |
     14. |  5   2012   4        2 |
     15. |  5   2013   3        3 |
         +------------------------+

    Comment


    • #3
      Thanks. This is helpful

      Comment

      Working...
      X