Dear Stata users,
I have the following panel data set covering all 50 states over 13 years.
The dataset is 4 variable wide and 452,755 observations long because each state year contains individual responses to a survey question about gubernatorial approval. Thus, there are 495 observations for Alabama in 2006, 131 obs for Alaska in 2006 etc. I would like to reshape the dataset and create 6 variables " Strongly_Approve", "Approve", "Disapprove", "Strongly_Disapprove", "Never_Heard", "Neither_Approve_Nor_Disapprove" instead of "approval_gov". Each of these 6 new variables would count the number of occurrences of each type of response in a given state year so that my dataset is 650 observations long (50 states by 13 years). There are about 2,000 missing values in approval_gov, which can be ignored/dropped. I tried to use `reshape`, but it does not seem to be able to give me what I want. I would be grateful for any help.
I have the following panel data set covering all 50 states over 13 years.
Code:
. describe obs: 452,755 vars: 4 3 Mar 2020 23:39 size: 7,244,080 ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- storage display value variable name type format label variable label ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- year long %12.0g CCES year state long %12.0g state State (FIPS) st long %12.0g st State abbreviation (FIPS) approval_gov long %12.0g approval_gov Governor approval ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Sorted by: . tab approval_gov,m Governor approval | Freq. Percent Cum. ---------------------------------+----------------------------------- Strongly Approve | 67,404 14.89 14.89 Approve / Somewhat Approve | 139,940 30.91 45.80 Disapprove / Somewhat Disapprove | 84,271 18.61 64.41 Strongly Disapprove | 117,282 25.90 90.31 Never Heard / Not Sure | 40,318 8.91 99.22 Neither Approve Nor Disapprove | 1,414 0.31 99.53 . | 2,126 0.47 100.00 ---------------------------------+----------------------------------- Total | 452,755 100.00 . tab approval_gov,m nolab Governor | approval | Freq. Percent Cum. ------------+----------------------------------- 1 | 67,404 14.89 14.89 2 | 139,940 30.91 45.80 3 | 84,271 18.61 64.41 4 | 117,282 25.90 90.31 5 | 40,318 8.91 99.22 6 | 1,414 0.31 99.53 . | 2,126 0.47 100.00 ------------+----------------------------------- Total | 452,755 100.00 . tab year CCES year Freq. Percent Cum. 2006 36,421 8.04 8.04 2007 9,999 2.21 10.25 2008 32,800 7.24 17.50 2009 13,800 3.05 20.55 2010 55,400 12.24 32.78 2011 20,150 4.45 37.23 2012 54,535 12.05 49.28 2013 16,400 3.62 52.90 2014 56,200 12.41 65.31 2015 14,250 3.15 68.46 2016 64,600 14.27 82.73 2017 18,200 4.02 86.75 2018 60,000 13.25 100.00 Total 452,755 100.00
Comment