load(url("http://bit.ly/dasi_gss_data"))
Base on the General Social Survey (GSS) Data Set, I want to find out how education level varied with the Political Party Affiliation.
I picked two variables from Data Set - Respondent Background Variables - educ: Highest year of school completed - Personal and Family Information - partyid: Political party affiliation
This extract of the General Social Survey (GSS) Cumulative File 1972-2012 provides a sample of selected indicators in the GSS with the goal of providing a convenient data resource for students learning statistical reasoning using the R language.
Methodology mentioned from General Social Survey, 1972-2012 [Cumulative File] (ICPSR 34802) ##### Sample:
For sampling information, please see Appendix A of the ICPSR Codebook.
Due to the number of weights and various uses for them, users should refer to Appendix A of the ICPSR Codebook.
computer-assisted personal interview (CAPI), face-to-face interview, telephone interview
ICPSR data undergo a confidentiality review and are altered when necessary to limit the risk of disclosure. ICPSR also routinely creates ready-to-go data files along with setups in the major statistical software formats as well as standard codebooks to accompany the data.
In addition to these procedures, ICPSR performed the following processing steps for this data collection:
- Created online analysis version with question text.
- Checked for undocumented or out-of-range codes.
Smith, Tom W., Michael Hout, and Peter V. Marsden. General Social Survey, 1972-2012 [Cumulative File]. ICPSR34802-v1. Storrs, CT: Roper Center for Public Opinion Research, University of Connecticut /Ann Arbor, MI: Inter-university Consortium for Political and Social Research [distributors], 2013-09-11. doi:10.3886/ICPSR34802.v1
na_count <- sapply(gss, function(y) sum(is.na(y)) )
name <- names(gss)
dim(gss)
## [1] 57061 114
table(gss$partyid)
##
## Strong Democrat Not Str Democrat Ind,Near Dem
## 9117 12040 6743
## Independent Ind,Near Rep Not Str Republican
## 8499 4921 9005
## Strong Republican Other Party
## 5548 861
na_count[which(name == "partyid")]
## partyid
## 327
table(gss$educ)
##
## 0 1 2 3 4 5 6 7 8 9 10 11
## 151 41 142 238 309 386 752 845 2598 1920 2635 3396
## 12 13 14 15 16 17 18 19 20
## 17493 4742 6170 2513 6988 1684 1977 760 1157
na_count[which(name == "educ")]
## educ
## 164
Insert exploratory data analysis here…
x <- "partyid"
y <- "educ"
par(mfrow = c(1, 1), mar = c(4, 4, 2, 0))
boxplot(as.formula(paste(y, "~", x)), data=data.rep.dem,
main ="How Education Level varied with Political Party affiliation",
las = 0, pch=10, cex = 1,
cex.axis = 0.6, cex.lab = 1,
col = "lightblue", xlab = "Political Party Affiliation",
ylab = "Highest year of school completed",
border ="blue", boxwex = 0.5)
According the plot shows people Political Party Affiliation tend to Republican Party has larger “Highest year of school completed”
summary(gss)
## caseid year age sex
## Min. : 1 Min. :1972 Min. :18.0 Male :25146
## 1st Qu.:14266 1st Qu.:1983 1st Qu.:31.0 Female:31915
## Median :28531 Median :1993 Median :43.0
## Mean :28531 Mean :1992 Mean :45.7
## 3rd Qu.:42796 3rd Qu.:2002 3rd Qu.:59.0
## Max. :57061 Max. :2012 Max. :89.0
## NA's :202
## race hispanic
## White:46350 Not Hispanic :16936
## Black: 7926 Mexican, Mexican American, Chicano/A: 1204
## Other: 2785 Puerto Rican : 258
## Spanish : 83
## Cuban : 77
## (Other) : 362
## NA's :38141
## uscitzn
## A U.S. Citizen : 375
## Not A U.S. Citizen : 378
## A U.S. Citizen Born In Puerto Rico, The U.S. Virgin Islands, Or The Northern Marianas Islands : 6
## Born Outside Of The United States To Parents Who Were U.S Citizens At That Time (If Volunteered): 11
## NA's :56291
##
##
## educ paeduc maeduc speduc
## Min. : 0.00 Min. : 0.00 Min. : 0.00 Min. : 0.00
## 1st Qu.:12.00 1st Qu.: 8.00 1st Qu.: 8.00 1st Qu.:12.00
## Median :12.00 Median :12.00 Median :12.00 Median :12.00
## Mean :12.75 Mean :10.55 Mean :10.71 Mean :12.78
## 3rd Qu.:15.00 3rd Qu.:13.00 3rd Qu.:12.00 3rd Qu.:15.00
## Max. :20.00 Max. :20.00 Max. :20.00 Max. :20.00
## NA's :164 NA's :16888 NA's :10132 NA's :27435
## degree vetyears sei
## Lt High School:11822 None :18093 Min. :17.10
## High School :29287 Less Than 2 Yrs : 816 1st Qu.:32.40
## Junior College: 3070 2 To 4 Years : 2123 Median :39.00
## Bachelor : 8002 More Than 4 Yrs : 847 Mean :48.42
## Graduate : 3870 Some,Dk How Long: 5 3rd Qu.:63.50
## NA's : 1010 NA's :35177 Max. :97.20
## NA's :25784
## wrkstat wrkslf marital
## Working Fulltime:28207 Self-Employed: 6197 Married :30761
## Keeping House : 9387 Someone Else :47352 Widowed : 5540
## Retired : 7642 NA's : 3512 Divorced : 7070
## Working Parttime: 5842 Separated : 1984
## Unempl, Laid Off: 1873 Never Married:11686
## (Other) : 4096 NA's : 20
## NA's : 14
## spwrksta sibs childs agekdbrn
## Working Fulltime:16815 Min. : 0.00 Min. :0.000 Min. : 9.00
## Keeping House : 5501 1st Qu.: 2.00 1st Qu.:0.000 1st Qu.:20.00
## Retired : 3561 Median : 3.00 Median :2.000 Median :23.00
## Working Parttime: 2743 Mean : 3.94 Mean :1.953 Mean :23.79
## Temp Not Working: 598 3rd Qu.: 5.00 3rd Qu.:3.000 3rd Qu.:27.00
## (Other) : 1479 Max. :68.00 Max. :8.000 Max. :65.00
## NA's :26364 NA's :1679 NA's :181 NA's :38942
## incom16 born parborn
## Far Below Average : 3725 Yes :43705 Both In U.S :39137
## Below Average :10692 No : 4099 Neither In U.S: 5881
## Average :21941 NA's: 9257 Mother Only : 1512
## Above Average : 6575 Father Only : 1047
## Far Above Average : 796 Mother; Fa. Dk: 92
## Lived In Institution: 10 (Other) : 97
## NA's :13322 NA's : 9295
## granborn income06 coninc
## Min. :0.000 $60000 To 74999 : 891 Min. : 383
## 1st Qu.:0.000 Refused : 860 1st Qu.: 18445
## Median :0.000 $40000 To 49999 : 836 Median : 35602
## Mean :1.155 $50000 To 59999 : 734 Mean : 44503
## 3rd Qu.:2.000 $75000 To $89999: 693 3rd Qu.: 59542
## Max. :4.000 (Other) : 6056 Max. :180386
## NA's :12065 NA's :46991 NA's :5829
## region partyid
## South Atlantic :10977 Not Str Democrat :12040
## E. Nor. Central:10572 Strong Democrat : 9117
## Middle Atlantic: 8435 Not Str Republican: 9005
## Pacific : 7630 Independent : 8499
## W. Sou. Central: 5363 Ind,Near Dem : 6743
## W. Nor. Central: 4221 (Other) :11330
## (Other) : 9863 NA's : 327
## polviews relig attend
## Moderate :18494 Protestant:33472 Every Week :11383
## Slightly Conservative: 7691 Catholic :13926 Once A Year : 7476
## Conservative : 7092 None : 6113 Sevrl Times A Yr: 7202
## Slightly Liberal : 6181 Jewish : 1155 2-3X A Month : 5060
## Liberal : 5582 Other : 998 More Thn Once Wk: 4370
## (Other) : 2836 (Other) : 1164 (Other) :11601
## NA's : 9185 NA's : 233 NA's : 9969
## natspac natenvir natheal
## Too Little : 3941 Too Little :19259 Too Little :21294
## About Right:12655 About Right: 9539 About Right: 8832
## Too Much :14631 Too Much : 2816 Too Much : 1955
## NA's :25834 NA's :25447 NA's :24980
##
##
##
## natcity natcrime natdrug
## Too Little :14842 Too Little :21500 Too Little :19555
## About Right: 9522 About Right: 8374 About Right: 9218
## Too Much : 4732 Too Much : 1907 Too Much : 2642
## NA's :27965 NA's :25280 NA's :25646
##
##
##
## nateduc natrace natarms
## Too Little :20619 Too Little :10458 Too Little : 7427
## About Right: 9374 About Right:13744 About Right:13675
## Too Much : 2262 Too Much : 6107 Too Much :10325
## NA's :24806 NA's :26752 NA's :25634
##
##
##
## nataid natfare natroad
## Too Little : 1934 Too Little : 6525 Too Little :14701
## About Right: 7286 About Right: 9888 About Right:18954
## Too Much :22286 Too Much :15345 Too Much : 3840
## NA's :25555 NA's :25303 NA's :19566
##
##
##
## natsoc natmass natpark
## Too Little :21443 Too Little :13636 Too Little :12535
## About Right:13582 About Right:18264 About Right:22861
## Too Much : 2335 Too Much : 3734 Too Much : 2345
## NA's :19701 NA's :21427 NA's :19320
##
##
##
## confinan conbus conclerg
## A Great Deal: 9015 A Great Deal: 8950 A Great Deal:10649
## Only Some :19659 Only Some :22628 Only Some :18958
## Hardly Any : 6379 Hardly Any : 5597 Hardly Any : 7755
## NA's :22008 NA's :19886 NA's :19699
##
##
##
## coneduc confed conlabor
## A Great Deal:11692 A Great Deal: 6319 A Great Deal: 4461
## Only Some :21322 Only Some :19535 Only Some :20159
## Hardly Any : 5208 Hardly Any :11783 Hardly Any :11884
## NA's :18839 NA's :19424 NA's :20557
##
##
##
## conpress conmedic contv
## A Great Deal: 6128 A Great Deal:17931 A Great Deal: 5183
## Only Some :20346 Only Some :17159 Only Some :20484
## Hardly Any :11465 Hardly Any : 3222 Hardly Any :12482
## NA's :19122 NA's :18749 NA's :18912
##
##
##
## conjudge consci conlegis
## A Great Deal:12091 A Great Deal:15362 A Great Deal: 4899
## Only Some :19460 Only Some :17796 Only Some :21756
## Hardly Any : 5551 Hardly Any : 2613 Hardly Any :10959
## NA's :19959 NA's :21290 NA's :19447
##
##
##
## conarmy joblose jobfind
## A Great Deal:14940 Very Likely : 937 Very Easy : 4865
## Only Some :17998 Fairly Likely : 1103 Somewhat Easy: 6120
## Hardly Any : 4709 Not Too Likely : 4830 Not Easy : 7687
## NA's :19414 Not Likely :11897 NA's :38389
## Leaving Labor Force: 5
## NA's :38289
##
## satjob richwork jobinc
## Very Satisfied :19717 Continue Working:15383 Most Impt: 4429
## Mod. Satisfied :15736 Stop Working : 6565 Second : 4974
## A Little Dissat : 4109 NA's :35113 Third : 6034
## Very Dissatisfied: 1715 Fourth : 3607
## NA's :15784 Fifth : 1528
## NA's :36489
##
## jobsec jobhour jobpromo jobmeans
## Most Impt: 1739 Most Impt: 952 Most Impt: 3810 Most Impt: 9641
## Second : 2781 Second : 1835 Second : 7082 Second : 3899
## Third : 4133 Third : 2334 Third : 4824 Third : 3245
## Fourth : 6516 Fourth : 4913 Fourth : 3085 Fourth : 2450
## Fifth : 5405 Fifth :10537 Fifth : 1769 Fifth : 1333
## NA's :36487 NA's :36490 NA's :36491 NA's :36493
##
## class rank satfin
## Lower Class : 3147 Min. : 1.00 Satisfied :15344
## Working Class:24458 1st Qu.: 4.00 More Or Less :23176
## Middle Class :24289 Median : 5.00 Not At All Sat:13934
## Upper Class : 1741 Mean : 4.77 NA's : 4607
## No Class : 1 3rd Qu.: 6.00
## NA's : 3425 Max. :10.00
## NA's :47207
## finalter finrela unemp govaid
## Better :19697 Far Below Average: 2891 Yes :10990 Yes : 4325
## Worse :11967 Below Average :12599 No :24517 No : 7760
## Stayed Same:20654 Average :25957 NA's:21554 NA's:44976
## NA's : 4743 Above Average : 9623
## Far Above Average: 1045
## NA's : 4946
##
## getaid union getahead
## Yes : 281 R Belongs : 4424 Hard Work :23022
## No : 1179 Spouse Belongs : 2056 Both Equally: 7834
## NA's:55601 R And Spouse Belong: 628 Luck Or Help: 4085
## Neither Belongs :32270 Other : 36
## NA's :17683 NA's :22084
##
##
## parsol kidssol abdefect
## Much Better : 4873 Much Better : 3587 Yes :31428
## Somewhat Better: 4539 Somewhat Better : 4228 No : 7788
## About The Same : 3214 About The Same : 2762 NA's:17845
## Somewhat Worse : 1655 Somewhat Worse : 1817
## Much Worse : 546 Much Worse : 614
## NA's :42234 No Children -Volunteered-: 1589
## NA's :42464
## abnomore abhlth abpoor abrape absingle
## Yes :17245 Yes :35321 Yes :18471 Yes :31865 Yes :17241
## No :21848 No : 4063 No :20557 No : 7116 No :21779
## NA's:17968 NA's:17677 NA's:18033 NA's:18080 NA's:18041
##
##
##
##
## abany pillok sexeduc
## Yes :12887 Strongly Agree : 5571 Favor :26501
## No :18920 Agree : 6459 Oppose : 4170
## NA's:25254 Disagree : 4691 Depends: 9
## Strongly Disagree: 4027 NA's :26381
## NA's :36313
##
##
## divlaw premarsx teensex
## Easier : 9155 Always Wrong : 9244 Always Wrong :15165
## More Difficult:16382 Almst Always Wrg: 3200 Almst Always Wrg: 3540
## Stay Same : 7147 Sometimes Wrong : 7044 Sometimes Wrong : 2106
## NA's :24377 Not Wrong At All:14060 Not Wrong At All: 891
## Other : 0 Other : 0
## NA's :23513 NA's :35359
##
## xmarsex homosex suicide1
## Always Wrong :25929 Always Wrong :21601 Yes :15924
## Almst Always Wrg: 4581 Almst Always Wrg: 1581 No :12902
## Sometimes Wrong : 2652 Sometimes Wrong : 2243 NA's:28235
## Not Wrong At All: 857 Not Wrong At All: 7282
## Other : 0 Other : 82
## NA's :23042 NA's :24272
##
## suicide2 suicide3 suicide4 fear owngun
## Yes : 2477 Yes : 2514 Yes : 4579 Yes :14010 Yes :14000
## No :27097 No :26990 No :24629 No :20285 No :20144
## NA's:27487 NA's:27557 NA's:27853 NA's:22766 Refused: 315
## NA's :22602
##
##
##
## pistol shotgun rifle news
## Yes : 7418 Yes : 8457 Yes : 8309 Everyday :17023
## No :26479 No :25432 No :25580 Few Times A Week : 7654
## Refused: 322 Refused: 322 Refused: 322 Once A Week : 4599
## NA's :22842 NA's :22850 NA's :22850 Less Than Once Wk: 3608
## Never : 2805
## NA's :21372
##
## tvhours racdif1 racdif2 racdif3 racdif4
## Min. : 0.000 Yes : 9630 Yes : 3434 Yes :12005 Yes :12765
## 1st Qu.: 2.000 No :14456 No :20987 No :12454 No :11062
## Median : 2.000 NA's:32975 NA's:32640 NA's:32602 NA's:33234
## Mean : 2.971
## 3rd Qu.: 4.000
## Max. :24.000
## NA's :23206
## helppoor helpnot
## Govt Action : 4806 Govt Do More : 4061
## Agree With Both :12273 Agree With Both :10874
## People Help Selves: 3087 Govt Does Too Much: 4137
## NA's :36895 NA's :37989
##
##
##
## helpsick helpblk
## Govt Should Help : 8241 Govt Help Blks : 2688
## Agree With Both : 8903 Agree With Both : 8540
## People Help Selves: 2183 No Special Treatment: 8656
## NA's :37734 NA's :37177
##
##
##