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

  • Unemployment Rate Calculation

    Hi everyone, new to Stata here and would love some help. Working on a college thesis project in which I have CPS data. Each row is an individual and the variables include year, state, and a dummy variable for employment status (0=employed, 1 = unemployed, 2 = not in labor force). I am trying to calculate unemployment rate by year and by state (for instance, for all the individuals living in Maine, what is the number of people with employment states 1 divided by the number of people with employment status 0 + number of people with employment status 1) but am unsure of how to do so without hardcoding values (I have been experimenting using 'count if' but have been unsuccessful. Any help would be much appreciated!
    Last edited by Benjamin Ethan; 15 Nov 2021, 11:52.

  • #2
    Something like this:
    by state year, sort: egen labor_force = total(inlist(employment_status, 0, 1))
    by state year: egen total_unemployed = total(employment_status == 1)
    gen unemployment_rate = total_unemployed/labor_force
    If you want the unemployment rate as a percent, just multiply the end result by 100.

    Note: As no example data was provided, this code is untested and may contain typos or other errors. It also may be incompatible with your actual data, since it was written for a data set I imagine you might have. To remove guesswork and increase the chances that you will get helpful responses on this forum, always show example data when asking for help with code. And always use the -dataex- command to do that. If you are running version 17, 16 or a fully updated version 15.1 or 14.2, -dataex- is already part of your official Stata installation. If not, run -ssc install dataex- to get it. Either way, run -help dataex- to read the simple instructions for using it. -dataex- will save you time; it is easier and quicker than typing out tables. It includes complete information about aspects of the data that are often critical to answering your question but cannot be seen from tabular displays or screenshots. It also makes it possible for those who want to help you to create a faithful representation of your example to try out their code, which in turn makes it more likely that their answer will actually work in your data.

    When asking for help with code, always show example data. When showing example data, always use -dataex-.


    • #3
      This worked perfectly, much appreciated! Will make sure to use -dataex- command going forward. Thanks for the help.