Announcement

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

  • proportion of a variable in a year for repeated cross section data

    I'd like to see what's the share of employed people in the labor force ( employed + unemployed ) in a county for every year available in my sample ( 2000-2021)

    So, my target coding is share = (total employed people in a county for a specific year) ) / ( total employed in a county for a specific year+ total unemployed in a county for a specific year )

    I want to find this ratio for every county for each year available in my sample (2000-2021)

    How can I code this up in Stata ? I have given sample data for convenience.

    If employed takes the value 0 , it doesn't mean unemployment will take the value 1. It could be that person is out of labor force. So, both of the variable could show up value 0 in some cases.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input int year double county float(employed unemployed)
    2018 1003 1 0
    2012 1003 0 1
    2012 1003 1 0
    2012 1005 1 0
    2019 1005 1 0
    2015 1005 0 1
    2015 1005 0 0
    2005 1007 0 0
    2018 1007 1 0
    2020 1007 1 0
    2007 1007 1 0
    2015 1007 0 1
    2012 1009 1 0
    2009 1009 1 0
    2012 1009 0 1
    end
    Last edited by Tariq Abdullah; 05 Sep 2022, 05:54.

  • #2
    If you don't care to retain the data in it existing form, you could simply use -collapse- :

    Code:
    collapse (sum) employed unemployed, by(county year)
    gen share = employed/(employed + unemployed)
    sort county year
    li county year share, noobs sepby(county)
    Alternatively, if do you want to retain the data in its present form, you could do:
    Code:
    sort county year
    by county year: egen tot_emp = sum(employed)
    by county year: egen tot_unemp = sum(unemployed)
    gen share = tot_emp/(tot_emp + tot_unemp)
    egen tag = tag(year county)
    li county year share if tag, noobs sepby(county)
    Either of these produce:
    Code:
      +-----------------------+
      | county   year   share |
      |-----------------------|
      |   1003   2012      .5 |
      |   1003   2018       1 |
      |-----------------------|
      |   1005   2012       1 |
      |   1005   2015       0 |
      |   1005   2019       1 |
      |-----------------------|
      |   1007   2005       . |
      |   1007   2007       1 |
      |   1007   2015       0 |
      |   1007   2018       1 |
      |   1007   2020       1 |
      |-----------------------|
      |   1009   2009       1 |
      |   1009   2012      .5 |
      +-----------------------+

    Comment


    • #3
      So kind and generous of you. Appreciate this thoughtfulness very much!

      Comment

      Working...
      X