0

I'm a very newbie with R.

I'm currently working on my dissertation using March CPS data (United States).

I find the variable of state unemployment rates is necessary for the completion of my model, but has little idea about how to add it in my dataset.

Currently, the dimension of my raw data is 633534 observations and 61 variables.

I have six separate years 2008 2009 2010 2012 2013 2014, and 52 states, which means I need 312 unemployment rate inputs for each year and each state. I know the figure of it from US Bureau of Labor Statistics (https://www.bls.gov/bls/news-release/home.htm#SRGUNE)

How can I add it to my data in a sophisticated way, rather than manually?

Just for your information, I want to see this from View() as below. (the gestcen is the variable name for state, and each number is the unique number for state. For example 14 = Massachusetts and 91 = Washington)

         h_year  gestcen (state)    unemployment
1      |  2008      14                   7.5
2      |  2008      91                   6.3
3      |  2008      14                   7.5
4      |  2008      14                   7.5
.      |
.      |
.      |
633,534|  2014      88                   9.2

Thanks for reading my messed up writing, and thanks in advance for your help!

Girim Ban
  • 21
  • 3
  • [http://www.dlt.ri.gov/lmi/laus/us/annavg.htm](http://www.dlt.ri.gov/lmi/laus/us/annavg.htm), you can download it there – astrofunkswag Mar 08 '20 at 19:33
  • Thanks @astrofunkswag for the info. But I can I merge this into my orginal dataset? I'm confused about which function to use after import the data into R studio – Girim Ban Mar 08 '20 at 20:31
  • Yes, the function is called 'merge'. You will want to create a variable in each data set that is a combination of state and year, then merge the two tables 'by' the columns you created in each table. – mgriebe Mar 08 '20 at 22:30
  • Thanks @mgriebe. Just one more question about merge function. As you might know, the number of observation in the raw data is over 630,000, whereas the number of states is only 52 and 6 year time period. In this case, how can I merge the data? – Girim Ban Mar 08 '20 at 23:54
  • You 'merge' using an matched index. It's not a cbind. So, you make a column where the entries look like "TX-2012" or "NJ-2008", (whatever applies to the row), in both to tables. Merge your table, with the downloaded table, 'by' the index you created. Merge will use entries in the first table to look up rows from the second table. Type ?merge into R console to learn more. – mgriebe Mar 09 '20 at 00:28

0 Answers0