/***** Replication File for Davenport (2016), "Beyond Black and White" *****/ /**** Lauren Davenport, Stanford University ****/ /**** Variable Coding, Tables 1-5, Appendix Table 3 in Stata ****/ /************************************/ cd "C:\Users\Lauren\Dropbox\Shared with Will\Davenport Papers\Politics Between Black and White\APSR submission 2013\Final Version May 2015\Code Files" /* Load in Freshman Survey Data 2001, 2002, 2003 received in 2012 */ use "DavenportDatasetFinal" drop y2001 /* wrong year variable from zip code information; use variable "year" instead */ drop y2002 drop y2003 drop y2004 drop y2005 /*** RESPONDENT RACIAL GROUPS ***/ tab RACE8 gen srace1=RACE8 /* Marks self as White */ tab srace1 tab RACE4 gen srace2=RACE4 /* Marks self as Black */ tab srace2 tab RACE1 gen srace3=RACE1 /* Marks self as American Indian */ tab srace3 tab RACE2 gen srace4=RACE2 /* Marks self as Asian */ tab srace4 tab RACE3 gen srace5=RACE3 /* Marks self as Pacific Islander */ tab srace5 tab RACE5 gen srace6=RACE5 /* Marks self as Mexican */ tab srace6 tab RACE6 gen srace7=RACE6 /* Marks self as Puerto Rican */ tab srace7 tab RACE7 gen srace8=RACE7 /* Marks self as Other Latino */ tab srace8 tab RACE9 gen srace9=RACE9 /* Marks self as Other */ tab srace9 /* ************************************************ */ /* CODING FATHER'S & MOTHER's RACE */ /* 1=White Only, 2=Black Only, 3=All Other Combinations */ gen FatherRace = . replace FatherRace=1 if frace1==2 & frace2==1 & frace3==1 & frace4==1 & frace5==1 & frace6==1 & frace7==1 & frace8==1 & frace9==1 replace FatherRace=2 if frace1==1 & frace2==2 & frace3==1 & frace4==1 & frace5==1 & frace6==1 & frace7==1 & frace8==1 & frace9==1 replace FatherRace=3 if FatherRace!=1 & FatherRace!=2 label define FatherRace 1 "White Only" 2 "Black Only" 3 "All Other" label value FatherRace FatherRace gen MotherRace = . replace MotherRace=1 if mrace1==2 & mrace2==1 & mrace3==1 & mrace4==1 & mrace5==1 & mrace6==1 & mrace7==1 & mrace8==1 & mrace9==1 replace MotherRace=2 if mrace1==1 & mrace2==2 & mrace3==1 & mrace4==1 & mrace5==1 & mrace6==1 & mrace7==1 & mrace8==1 & mrace9==1 replace MotherRace=3 if MotherRace!=1 & MotherRace!=2 label define MotherRace 1 "White Only" 2 "Black Only" 3 "All Other" label value MotherRace MotherRace gen wfabmo = . replace wfabmo=1 if FatherRace==1 & MotherRace==2 /* If White Father, Black Mother*/ replace wfabmo=0 if FatherRace==2 & MotherRace==1 /* If Black Father, White Mother*/ /* ************************************************ */ /* RESPONDENT'S PARENTS RACE & IDENTITY */ gen BOTHblackwhite = 0 /* Identifies self as BOTH White and Black (Only) */ replace BOTHblackwhite=1 if srace1==2 & srace2==2 & srace3==1 & srace4==1 & srace5==1 & srace6==1 & srace7==1 & srace8==1 & srace9==1 /* Only Black and White are marked */ tab BOTHblackwhite gen PARbwID = . /* ID Groups for Biracials of White-Black parentage */ replace PARbwID=1 if RACEGROUP==5 & FatherRace==1 & MotherRace==2 /* If identifies self as White Only */ replace PARbwID=1 if RACEGROUP==5 & FatherRace==2 & MotherRace==1 replace PARbwID=2 if RACEGROUP==3 & FatherRace==1 & MotherRace==2 /* If identifies self as Black Only*/ replace PARbwID=2 if RACEGROUP==3 & FatherRace==2 & MotherRace==1 replace PARbwID=3 if BOTHblackwhite==1 & FatherRace==1 & MotherRace==2 /* If identifies self as White and Black Only*/ replace PARbwID=3 if BOTHblackwhite==1 & FatherRace==2 & MotherRace==1 replace PARbwID=4 if RACEGROUP==6 & FatherRace==1 & MotherRace==2 /* If identifies self as Other Race Only*/ replace PARbwID=4 if RACEGROUP==6 & FatherRace==2 & MotherRace==1 label define PARbwID 1 "White Only" 2 "Black Only" 3 "White-Black" 4 "Other Only" label value PARbwID PARbwID tab PARbwID gen racePARraceID=. /* ID Groups for Monoracial Whites, Biracial Whites, Biracial White-Blacks, Biracial Blacks, and Monoracial Blacks */ replace racePARraceID=1 if RACEGROUP==5 & FatherRace==1 & MotherRace==1 replace racePARraceID=2 if RACEGROUP==5 & FatherRace==1 & MotherRace==2 replace racePARraceID=2 if RACEGROUP==5 & FatherRace==2 & MotherRace==1 replace racePARraceID=3 if BOTHblackwhite==1 & FatherRace==1 & MotherRace==2 replace racePARraceID=3 if BOTHblackwhite==1 & FatherRace==2 & MotherRace==1 replace racePARraceID=4 if RACEGROUP==3 & FatherRace==1 & MotherRace==2 replace racePARraceID=4 if RACEGROUP==3 & FatherRace==2 & MotherRace==1 replace racePARraceID=5 if RACEGROUP==3 & FatherRace==2 & MotherRace==2 label define racePARraceID 1 "wPARwID" 2 "wbPARwID" 3 "wbPARwbID" 4 "wbPARbID" 5 "bPARbID" label values racePARraceID racePARraceID tab racePARraceID *************************** *************************** /*** OTHER DEMOGRAPHICS ***/ tab YEAR /* Survey year */ gen year=YEAR tab year tab OBEREGION gen obereg=OBEREGION /* OBE region */ tab obereg codebook SEX gen female=. /* Coding for gender */ replace female=1 if SEX==2 replace female=0 if SEX==1 tab female tab AGE1 gen age=AGE1 /* Age in yrs */ tab age tab NATENGSP gen natengsp=NATENGSP /* whether native English speaker */ tab natengsp tab MARITAL gen marital=MARITAL /* whether married */ tab marital tab CITIZEN gen citizen=CITIZEN /* US citizenship status */ label define citizen 1 "no/neither" 2 "permanent resident (green card)" 3 "yes U.S. citizen" label values citizen citizen tab citizen tab PARSTAT gen parstat=PARSTAT /* parents' relationship status */ recode parstat (1=2) (2=2) (3=1) label define parstat 1 "Parents Together" 2 "Parents not together or dead" label values parstat parstat tab parstat gen incomecat=INCOME /* Income */ recode incomecat (1 2 3 4 5 6 7 8 = 1) (9 10 11 12 13 14 15 16 = 2) (17 18 19 = 3) (20 21 22 23 24 25 = 4) label define incomecat 1 "less than $30,000" 2 "$30,000-$59,999" 3 "$60,000-$99,999" 4 "$100,000 or more" label values incomecat incomecat tab incomecat gen religionst=SRELIGION /* Student's Religious preference */ recode religionst (1=1) (13=2) (3 4 5 7 8 9 11 12 14 15 16=3) (6=4) (2=5) (10 17 =5) (18=6) label define religionst 1 "Baptist" 2 "Catholic" 3 "Other Christian" 4 "Jewish" 5 "Other Religion" 6 "No Religion" label values religionst religionst tab religionst /*** Region variables -- South, Pacific, Rest of Country */ /*** Eleven secessionist states plus KY, MO, OK and WV */ labelbook homest /* CORRECTING ERROR in this variable coding */ gen region=. replace region=2 if homest==11 /* AK*/ | homest==14 /* CA*/ | homest==47 /* OR*/ | homest==57 /* WA*/ | homest==21 /* HI*/ replace region=3 if homest==10 /* AL*/ | homest==13 /* AR*/ | homest==17 /*DE */ | homest==19 /* FL*/ | homest==20 /* GA*/ | homest==27 /* KY*/ | homest==28 /* LA*/ | homest==35 /* MO*/ | homest==34 /* MS*/ | homest==43 /* NC*/ | homest==46 /* OK*/ | homest==50 /* SC*/ | homest==52 /* TN*/ | homest==53 /* TX*/ | homest==56 /* VA*/ | homest==58 /* WV*/ replace region=1 if homest!=. & region!=2 & region!=3 & homest!=62 /* All states that are not missing data, non-South, non-Pacific, and non-Other */ label define region 1 "Not South, Not Pacific" 2 "Pacific" 3 "South" label values region region tab region /* NEW VARIABLE: 5 Regional Categories, treating "Other" responses (n=2,382) as missing */ gen region5=. replace region5=1 if homest==11 /* AK*/ | homest==14 /* CA*/ | homest==21 /* HI*/ | homest==47 /* OR*/ | homest==57 /* WA*/ replace region5=2 if homest==10 /* AL*/ | homest==13 /* AR*/ | homest==17 /*DE */ | homest==19 /* FL*/ | homest==20 /* GA*/ | homest==27 /* KY*/ | homest==28 /* LA*/ | homest==34 /* MS*/ | homest==35 /* MO*/ | homest==43 /* NC*/ | homest==46 /* OK*/ | homest==50 /* SC*/ | homest==52 /* TN*/ | homest==53 /* TX*/ | homest==56 /* VA*/ | homest==58 /* WV*/ replace region5=3 if homest==12 /* AZ */ | homest==15 /*CO */ | homest==22 /*ID*/ | homest==26 /* KS */ | homest==36 /*MT*/ | homest==37 /*NE*/ | homest==38 /*NV*/ | homest==41 /*NM*/ | homest==44 /*ND*/ | homest==51 /*SD*/ | homest==54 /*UT*/ | homest==60 /*WY*/ replace region5=4 if homest==16 /* CT */ | homest==18 /* DC */ | homest==29 /* ME */ | homest==30 /* MD*/ | homest==31 /* MA*/ | homest==39 /*NH*/ | homest==40 /*NJ*/ | homest==42 /* NY */ | homest==48 /*PA*/ | homest==49 /*RI*/ | homest==55 /*VT*/ replace region5=5 if homest==23 /*IL*/ | homest==24 /*IN*/ | homest==25 /*IA*/ | homest==32 /* MI */ | homest==33 /* MN */ | homest==45 /* OH */ | homest==59 /*WI*/ label define region5 1 "Pacific" 2 "South" 3 "Mountains/Plains" 4 "Northeast" 5 "Midwest" label values region5 region5 tab region5 ****************************************** ****************************************** /* PARENT'S EDUCATION/CAREERS*/ tab FATHEDUC /* Father's education */ gen eduF=FATHEDUC recode eduF (0 1 2 3 =1) (4 5=2) (6=3) (7 8=4) label define eduF 1 "HS diploma or less" 2 "Some college" 3 "College grad" 4 "Grad school" label value eduF eduF tab eduF tab MOTHEDUC /* Mother's education */ gen eduM=MOTHEDUC recode eduM (0 1 2 3 =1) (4 5=2) (6=3) (7 8=4) label define eduM 1 "HS diploma or less" 2 "Some college" 3 "College grad" 4 "Grad school" label value eduM eduM tab eduM gen eduB=. /* Black Parent's education, for White-Black Kids */ replace eduB=1 if wfabmo==0 & eduF==1 /* if has Black father with at most hs diploma */ replace eduB=2 if wfabmo==0 & eduF==2 /* if has Black father with some college */ replace eduB=3 if wfabmo==0 & eduF==3 /* if has Black father with college degree */ replace eduB=4 if wfabmo==0 & eduF==4 /* if has Black father with grad schooling */ replace eduB=1 if wfabmo==1 & eduM==1 /* if has Black mother with at most hs diploma */ replace eduB=2 if wfabmo==1 & eduM==2 /* if has Black mother with some college */ replace eduB=3 if wfabmo==1 & eduM==3 /* if has Black mother with college degree */ replace eduB=4 if wfabmo==1 & eduM==4 /* if has Black mother with grad schooling */ label define eduB 1 "HS diploma or less" 2 "Some college" 3 "College grad" 4 "Grad school" label value eduB eduB tab eduB gen eduW=. /* White Parent's education, for White-Black Kids */ replace eduW=1 if wfabmo==1 & eduF==1 /* if has White father with at most hs diploma*/ replace eduW=2 if wfabmo==1 & eduF==2 /* if has White father with some college */ replace eduW=3 if wfabmo==1 & eduF==3 /* if has White father with college degree */ replace eduW=4 if wfabmo==1 & eduF==4 /* if has White father with grad schooling */ replace eduW=1 if wfabmo==0 & eduM==1 /* if has White mother with at most hs diploma */ replace eduW=2 if wfabmo==0 & eduM==2 /* if has White mother with some college */ replace eduW=3 if wfabmo==0 & eduM==3 /* if has White mother with college degree */ replace eduW=4 if wfabmo==0 & eduM==4 /* if has White mother with grad schooling */ label define eduW 1 "HS diploma or less" 2 "Some college" 3 "College grad" 4 "Grad school" label value eduW eduW tab eduW ****************************************** ****************************************** /* Generating Quartiles for Population Density */ gen popdensity=. replace popdensity=1 if PopDensity < 283.4 /* Bottom quartile; 25% of PopDensity is 283.4 or less */ replace popdensity=2 if PopDensity >= 283.4 & PopDensity < 1238.2 /* 25% of PopDensity is 283.4 and 50% of PopDensity is 1238.2 */ replace popdensity=3 if PopDensity >= 1238.2 & PopDensity < 3435.4 /* 50% of PopDensity is 1238.2 and 75% of PopDensity is 3435.4 */ replace popdensity=4 if PopDensity >= 3435.4 /* Top quartile; 75% and higher of PopDensity is 3435.4 and above */ replace popdensity=. if PopDensity==. /* Coding as missing data people who don't give a valid zip code */ label define popdensity 1 "Lower Quartile" 2 "25-49.9" 3 "50-74.9" 4 "Upper Quartile" label values popdensity popdensity tab popdensity /* Generating Quartiles for Household Income */ gen hhincome=. replace hhincome=1 if HouseholdIncome < 37440 /* Bottom quartile; 25% of HouseholdIncome is 37440 or less */ replace hhincome=2 if HouseholdIncome >= 37440 & HouseholdIncome < 49214 /* 25% of HouseholdIncome is 37440 and 50% of HouseholdIncome is 49214 */ replace hhincome=3 if HouseholdIncome >= 49214 & HouseholdIncome < 64256 /* 50% of HouseholdIncome is 49214 and 75% of HouseholdIncome is 64256 */ replace hhincome=4 if HouseholdIncome >= 64256 /* Top quartile; 75% and higher of HouseholdIncome is 64256 and above */ replace hhincome=. if HouseholdIncome==. /* Coding as missing data people who don't give a valid zip code */ label define hhincome 1 "Lower Quartile" 2 "25-49.9" 3 "50-74.9" 4 "Upper Quartile" label values hhincome hhincome tab hhincome /* Generating Quartiles for Percent Black, non-Hispanic */ gen percentblack=. replace percentblack=1 if Black_NH < .007814 /* Bottom quartile; 25% of Black_NH is .007814 or less */ replace percentblack=2 if Black_NH >= 0.007814 & Black_NH < 0.024284 /* 25% of Black_NH is 0.007814 and 50% of Black_NH is 0.024284 */ replace percentblack=3 if Black_NH >= 0.024284 & Black_NH < 0.079304 /* 50% of Black_NH is 0.024284 and 75% of Black_NH is 0.079304 */ replace percentblack=4 if Black_NH >= 0.079304 /* Top quartile; 75% and higher of Black_NH is 0.079304 and above */ replace percentblack=. if Black_NH==. /* Coding as missing data people who don't give a valid zip code */ label define percentblack 1 "Lower Quartile" 2 "25-49.9" 3 "50-74.9" 4 "Upper Quartile" label values percentblack percentblack tab percentblack /* *********************************** */ /* POLITICAL QUESTIONS*/ tab VIEWS02 /* Abortion should be legal */ gen abortion=VIEWS02 label define abortion 1 "Disagree strongly" 2 "Disagree somewhat" 3 "Agree somewhat" 4 "Agree strongly" label values abortion abortion tab abortion tab VIEWS04 /* Affirmative action in college admissions should be abolished *******/ gen affaction=VIEWS04 recode affaction (4=1) (3=2) (2=3) (1=4) label define affaction 1 "Agree strongly" 2 "Agree somewhat" 3 "Disagree somewhat" 4 "Disagree strongly" label values affaction affaction tab affaction tab VIEWS18 /* Racial discrimination no longer a major problem in America ******/ gen racismnoproblem=VIEWS18 recode racismnoproblem (4=1) (3=2) (2=3) (1=4) label define racismnoproblem 1 "Agree strongly" 2 "Agree somewhat" 3 "Disagree somewhat" 4 "Disagree strongly" label values racismnoproblem racismnoproblem tab racismnoproblem tab VIEWS20 /* Same-sex couples should have the right to legal marital status *******/ gen gaymarriage=VIEWS20 label define gaymarriage 1 "Disagree strongly" 2 "Disagree somewhat" 3 "Agree somewhat" 4 "Agree strongly" label values gaymarriage gaymarriage tab gaymarriage tab VIEWS21 /* Activities of married women best confined to home *******/ gen marriedwomen=VIEWS21 recode marriedwomen (4=1) (3=2) (2=3) (1=4) label define marriedwomen 1 "Agree strongly" 2 "Agree somewhat" 3 "Disagree somewhat" 4 "Disagree strongly" label values marriedwomen marriedwomen tab marriedwomen tab VIEWS23 /* Death penalty should be abolished *****/ gen deathpenalty=VIEWS23 label define deathpenalty 1 "Disagree strongly" 2 "Disagree somewhat" 3 "Agree somewhat" 4 "Agree strongly" label values deathpenalty deathpenalty tab deathpenalty tab VIEWS25 /* Federal government should do more to prevent sale of handguns *****/ gen preventguns=VIEWS25 label define preventguns 1 "Disagree strongly" 2 "Disagree somewhat" 3 "Agree somewhat" 4 "Agree strongly" label values preventguns preventguns tab preventguns tab VIEWS28 /* Too much concern for rights of criminals*/ gen rightscriminals=VIEWS28 recode rightscriminals (4=1) (3=2) (2=3) (1=4) label define rightscriminals 1 "Agree strongly" 2 "Agree somewhat" 3 "Disagree somewhat" 4 "Disagree strongly" label values rightscriminals rightscriminals tab rightscriminals /* **************************** */ /* GOALS AND VALUES; How important is it that you... *******/ tab GOAL13 /* Promote racial understanding ******/ gen promoteracial=GOAL13 label define promoteracial 1 "Not Important" 2 "Somewhat important" 3 "Very important" 4 "Essential" label values promoteracial promoteracial tab promoteracial ****************************************** ****************************************** /***** CODE FOR TABLES 1 and 2 *****/ /*** TABLE 1 ***/ /* How do people with 2 White parents identify? */ gen BOTHwhiteID=. replace BOTHwhiteID=1 if RACEGROUP==5 & FatherRace==1 & MotherRace==1 /* ID as White if Father=White and Mother=White */ replace BOTHwhiteID=2 if RACEGROUP==3 & FatherRace==1 & MotherRace==1 /* ID as Black if Father=White and Mother=White */ replace BOTHwhiteID=3 if BOTHblackwhite==1 & FatherRace==1 & MotherRace==1 /* ID as White-Black if Father=White and Mother=White */ tab BOTHwhiteID /* How do people with 2 Black parents identify? */ gen BOTHblackID=. replace BOTHblackID=1 if RACEGROUP==5 & FatherRace==2 & MotherRace==2 replace BOTHblackID=2 if RACEGROUP==3 & FatherRace==2 & MotherRace==2 replace BOTHblackID=3 if BOTHblackwhite==1 & FatherRace==2 & MotherRace==2 tab BOTHblackID /* How do people with 2 White parents identify? */ tab PARbwID if PARbwID<4 /*** TABLE 2 ***/ /* SAMPLE CHARACTERISTICS */ tab female racePARraceID, col tab region5 racePARraceID, col tab hhincome racePARraceID, col tab percentblack racePARraceID, col tab popdensity racePARraceID, col tab parstat racePARraceID, col tab religionst racePARraceID, col ************************************** ************************************** * RECODING POLITICAL ISSUES FOR TABLES 3, 4, 5 from 4-pt scale to 2-pt "Agree"/"Disagree" scale */ /*** TABLE 3 ***/ /* Coding Explicitly Racial Issues--Whether "Agree" or "Disagree" */ tab racismnoproblem /* Racial discrimination no longer a major problem in America ******/ gen racismnoproblem2=racismnoproblem recode racismnoproblem2 (1 2 = 1) (3 4 = 2) label define racismnoproblem2 1 "Agree" 2 "Disagree" /* reverse coded */ label values racismnoproblem2 racismnoproblem2 tab racismnoproblem2 tab GOAL13 /* Promote racial understanding ******/ gen promoteracial2=GOAL13 recode promoteracial2 (1 2 = 1) (3 4 = 2) label define promoteracial2 1 "Not or Somewhat Important" 2 "Very important or Essential" label values promoteracial2 promoteracial2 tab promoteracial2 tab affaction /* Affirmative action in college admissions should be abolished *******/ gen affaction2=affaction recode affaction2 (1 2 = 1) (3 4 =2) label define affaction2 1 "Agree" 2 "Disagree" label values affaction2 affaction2 tab affaction2 /* Crosstabs for TABLE 3 */ tab racismnoproblem2 racePARraceID, col tab promoteracial2 racePARraceID, col tab affaction2 racePARraceID, col ****************************************** ****************************************** /*** TABLE 4 ***/ /* Coding Implicitly Racial Issues--Whether "Agree" or "Disagree" */ tab rightscriminals /* Too much concern for rights of criminals*/ gen rightscriminals2=rightscriminals recode rightscriminals2 (1 2 = 1) (3 4 = 2) label define rightscriminals2 1 "Agree" 2 "Disagree" /* reverse coded */ label values rightscriminals2 rightscriminals2 tab rightscriminals2 tab deathpenalty /* Death penalty should be abolished *****/ gen deathpenalty2=deathpenalty recode deathpenalty2 (1 2 = 1) (3 4 = 2) label define deathpenalty2 1 "Disagree" 2 "Agree" label values deathpenalty2 deathpenalty2 tab deathpenalty2 tab preventguns /* Federal government should do more to prevent sale of handguns *****/ gen preventguns2=preventguns recode preventguns2 (1 2 = 1) (3 4 = 2) label define preventguns2 1 "Disagree" 2 "Agree" label values preventguns2 preventguns2 tab preventguns2 /* Crosstabs for TABLE 4 */ tab rightscriminals2 racePARraceID, col tab deathpenalty2 racePARraceID, col tab preventguns2 racePARraceID, col ****************************************** ****************************************** /*** TABLE 5 ***/ /* Coding Nonracial Issues--Whether "Agree" or "Disagree" */ gen abortion2=abortion recode abortion2 (1 2 = 1) (3 4 = 2) label define abortion2 1 "Disagree" 2 "Agree" label values abortion2 abortion2 tab abortion2 tab gaymarriage /* Same-sex couples should have the right to legal marital status *******/ gen gaymarriage2=gaymarriage recode gaymarriage2 (1 2 = 1) (3 4 = 2) label define gaymarriage2 1 "Disagree" 2 "Agree" label values gaymarriage2 gaymarriage2 tab gaymarriage2 tab marriedwomen /* Activities of married women best confined to home *******/ gen marriedwomen2=marriedwomen recode marriedwomen2 (1 2 = 1) (3 4 = 2) label define marriedwomen2 1 "Agree" 2 "Disagree" label values marriedwomen2 marriedwomen2 tab marriedwomen2 /* Crosstabs for TABLE 5 */ tab abortion2 racePARraceID, col tab marriedwomen2 racePARraceID, col tab gaymarriage2 racePARraceID, col *********************************** *********************************** /* APPENDIX-TABLE 3 */ /* Explaining Identification (White-Black Biracial Parentage) */ tab PARbwID if PARbwID<4 tab PARbwID wfabmo if PARbwID<4, col tab PARbwID parstat if PARbwID<4, col tab PARbwID female if PARbwID<4, col tab PARbwID incomecat if PARbwID<4, col tab PARbwID eduW if PARbwID<4, col tab PARbwID eduB if PARbwID<4, col tab PARbwID religionst if PARbwID<4, col tab PARbwID region5 if PARbwID<4, col tab PARbwID hhincome if PARbwID<4, col tab PARbwID popdensity if PARbwID<4, col tab PARbwID percentblack if PARbwID<4, col /* Sample Characteristics */ tab wfabmo if PARbwID<4 tab parstat if PARbwID<4 tab female if PARbwID<4 tab incomecat if PARbwID<4 tab eduW if PARbwID<4 tab eduB if PARbwID<4 tab religionst if PARbwID<4 tab region5 if PARbwID<4 tab hhincome if PARbwID<4 tab percentblack if PARbwID<4 tab popdensity if PARbwID<4 save "C:\Users\Lauren\Dropbox\Shared with Will\Davenport Papers\Politics Between Black and White\APSR submission 2013\Final Version May 2015\Code Files\DavenportDataset.dta" *********************************** *********************************** ############################################################################### ## Replication File for Davenport (2016), "Beyond Black and White" ## Lauren Davenport, Stanford University ## Graphs, Regressions, and Appendices in R ## July 5 2015 ############################################################################### # setwd("~/Downloads/BBW/scripts") source("functions.R") # setwd("~/Downloads/BBW/data") ## Load required packages, install if missing pkgs <- c( 'Amelia', 'car', 'descr', 'doParallel', 'foreach', 'foreign', 'MatchIt', 'MCMCpack', 'TeachingDemos', 'Zelig', 'VGAM', 'ZeligChoice') for (package in pkgs) { if (suppressPackageStartupMessages( !require(package, character.only = TRUE, quietly = TRUE))) { install.packages(package) suppressPackageStartupMessages( library(package, character.only = TRUE, quietly = TRUE) ) } suppressPackageStartupMessages( library(package, character.only = TRUE, quietly = TRUE) ) } ## Load data load("DavenportDataset.RData") colnames(df) ############################################# ## Register cluster for parallel processes ## ############################################# cores <- detectCores() inuse <- getDoParWorkers() free <- cores - inuse - 1 cl <- makeCluster(ifelse(free>1, free, 1)) registerDoParallel(cl) clusterEvalQ( cl, {library("Zelig"); library("ZeligChoice"); library("MatchIt");} ) ###################### ## Recode Variables ## ###################### # Take the log population density df$PopDensity[df$PopDensity==0] <- 0.05 # Only one case df$PopDensity <- log(df$PopDensity, base=10) # Median household income in zip, standardized by standard deviation df$HouseholdIncome <- df$HouseholdIncome / sd(df$HouseholdIncome, na.rm=T) # Factor year df$year <- as.factor(df$year) # 0 if not of white-black parentage df$wfabmo[is.na(df$wfabmo)] <- 0 # Set "No Religion" as baseline category df$religionst <- relevel(df$religionst, ref="No Religion") ####################################### ## ANALYSIS OF POLITICAL ATTITUDES ## ####################################### # Dependent variables for each regression model dvs <- c( "racismnoproblem", "promoteracial", "affaction", "rightscriminals", "deathpenalty", "preventguns", "abortion", "gaymarriage", "marriedwomen" ) # Independent variables used in all regression models ivs <- paste( "racePARraceID + wfabmo + female + region5 + eduF +", "eduM + incomecat + religionst + parstat + year +", "PopDensity + HouseholdIncome + Black_NH" ) ######## MONORACIAL WHITES V. BIRACIAL WHITES ######### # Subset to individuals who identify as white AND have either: # (1) 1 white + 1 black parent, OR # (2) two white parents wdat <- subset( df, racePARraceID=="wbPARwID" | racePARraceID=="wPARwID", select= c( "racePARraceID", "wfabmo", "female", "region5", "eduF", "eduM", "incomecat", "parstat", "religionst","year", "PopDensity", "HouseholdIncome", "Black_NH", "racismnoproblem", "promoteracial", "affaction", "rightscriminals", "deathpenalty", "preventguns", "abortion", "gaymarriage", "marriedwomen") ) wdat$treat <- ifelse(wdat$racePARraceID=="wbPARwID", 1, 0) # Re-factor racial parentage/self-identification variable wdat$racePARraceID <- factor(wdat$racePARraceID) wdat$racePARraceID <- relevel(wdat$racePARraceID, ref="wPARwID") wdat$row <- rownames(wdat) # Note: matchit will throw an error if data has missing values # hence, subset dataset to observations without NAs in variables used # for exact/nearest-neighbor matching tmp <- subset( wdat, !is.na(racePARraceID) & !is.na(wfabmo) & !is.na(female) & !is.na(region5) & !is.na(eduF) & !is.na(eduM) & !is.na(incomecat) & !is.na(parstat) & !is.na(religionst) & !is.na(PopDensity) & !is.na(HouseholdIncome) & !is.na(Black_NH), select=c( "racePARraceID", "wfabmo", "eduF", "eduM", "incomecat", "parstat", "religionst", "PopDensity", "HouseholdIncome", "Black_NH", "treat", "female", "year", "region5", "row") ) # Create matched dataset using: # (1) Exact matching on `female', `year' & `region', AND # (2) Nearest neighbor matching on `eduF', `eduM', `incomecat', `parstat', # `religionst', `PopDensity', `HouseholdIncome', `Black_NH` exact_values <- expand.grid( female=unique(tmp$female), year=unique(tmp$year), region5=unique(tmp$region5) ) exact_values$exact_match <- buckets <- 1:nrow(exact_values) tmp <- merge(tmp, exact_values, by=c("female", "year", "region5")) # Loop over levels of exact matches (here, buckets), # subsetting tmp dataset to only matched observations set.seed(937493) wdat.matched <- foreach(i = buckets, .combine = rbind, .errorhandling = "remove") %dopar% { bucket <- subset(tmp, subset = exact_match == i) m.out <- matchit( treat ~ eduF + eduM + incomecat + parstat + religionst + PopDensity + HouseholdIncome + Black_NH, data = bucket, ratio = 100, method = "nearest" ) match_rows <- c(rownames(m.out$match.matrix), as.vector(m.out$match.matrix)) bucket_matches <- match(rownames(bucket), match_rows) match_ids <- bucket$row[!is.na(bucket_matches)] return(wdat[match_ids, ]) } # Ordered logit on full data # m.whites <- parLapply(cl=cl, dvs, LogReg, ivs=ivs, dat=wdat) # APPENDIX TABLES 4, 7, AND 10 sink("ologit_results_whites.txt", append=TRUE) lapply(m.whites, summary) sink() # Ordered logit on matched data (for figures) m.whites.matched <- parLapply(cl=cl, dvs, LogReg, ivs=ivs, dat=wdat.matched) sink("matched_results_whites.txt", append=TRUE) lapply(m.whites.matched, summary) sink() ######## MONORACIAL BLACKS V. BIRACIAL BLACKS ######## ## Subset to individuals who identify as black and have either ## (1) 1 white + 1 black parent ## OR (2) two black parents bdat <- subset( df, racePARraceID=="wbPARbID" | racePARraceID=="bPARbID", select = c( "racePARraceID", "wfabmo", "female", "region5", "eduF", "eduM", "incomecat", "parstat", "religionst","year", "PopDensity", "HouseholdIncome", "Black_NH", "racismnoproblem", "promoteracial", "affaction", "rightscriminals", "deathpenalty", "preventguns", "abortion", "gaymarriage", "marriedwomen") ) bdat$treat <- ifelse(bdat$racePARraceID=="wbPARbID", 1, 0) bdat$racePARraceID <- as.factor(as.character(bdat$racePARraceID)) bdat$racePARraceID <- relevel(bdat$racePARraceID, ref="bPARbID") bdat$row <- rownames(bdat) # Further subset to observations without missing values on matching vars tmp <- subset( bdat, !is.na(racePARraceID) & !is.na(wfabmo) & !is.na(female) & !is.na(region5) & !is.na(eduF) & !is.na(eduM) & !is.na(incomecat) & !is.na(parstat) & !is.na(religionst) & !is.na(PopDensity) & !is.na(HouseholdIncome) & !is.na(Black_NH), select=c( "racePARraceID", "wfabmo", "eduF", "eduM", "incomecat", "parstat", "religionst", "PopDensity", "HouseholdIncome", "Black_NH", "treat", "female", "year", "region5", "row") ) # Exact match exact_values <- expand.grid( female=unique(tmp$female), year=unique(tmp$year), region5=unique(tmp$region5) ) exact_values$exact_match <- buckets <- 1:nrow(exact_values) tmp <- merge(tmp, exact_values, by=c("female", "year", "region5")) # KNN match set.seed(579897) bdat.matched <- foreach(i = buckets, .combine = rbind, .errorhandling = "remove") %dopar% { bucket <- subset(tmp, subset = exact_match == i) m.out <- matchit( treat ~ eduF + eduM + incomecat + parstat + religionst + PopDensity + HouseholdIncome + Black_NH, data = bucket, ratio = 100, method = "nearest" ) match_rows <- c(rownames(m.out$match.matrix), as.vector(m.out$match.matrix)) bucket_matches <- match(rownames(bucket), match_rows) match_ids <- bucket$row[!is.na(bucket_matches)] return(bdat[match_ids, ]) } # Ordered Logit on full data m.blacks <- parLapply(cl=cl, dvs, LogReg, ivs=ivs, dat=bdat) # APPENDIX TABLES 5, 8, AND 11 sink("ologit_results_blacks.txt") lapply(m.blacks, summary) sink() # Ordered Logit on matched data m.blacks.matched <- parLapply(cl=cl, dvs, LogReg, ivs=ivs, dat=bdat.matched) sink("matched_results_blacks.txt") lapply(m.blacks.matched, summary) sink() ######## ALL RESPONDENTS OF BIRACIAL PARENTAGE ######## wbdat <- subset( df, (racePARraceID=="wbPARbID" | racePARraceID=="wbPARwbID" | racePARraceID=="wbPARwID") & !is.na(racePARraceID) & !is.na(wfabmo) & !is.na(region5) & !is.na(eduF) & !is.na(eduM) & !is.na(incomecat) & !is.na(parstat) & !is.na(religionst) & !is.na(PopDensity) & !is.na(HouseholdIncome) & !is.na(Black_NH) & !is.na(female) ) # Baseline is Mixed White-Black wbdat$racePARraceID <- as.factor(as.character(wbdat$racePARraceID)) wbdat$racePARraceID <- relevel(wbdat$racePARraceID, ref="wbPARwbID") # Ordered Logit on full data m.whblk <- parLapply(cl=cl, dvs, LogReg, ivs = ivs, dat = wbdat) # APPENDIX TABLES 6, 9, AND 12 sink("ologit_results_biracials.txt", append=TRUE) lapply(m.whblk, summary) sink() ############## ## FIGURE 1 ## ############## # Father's Education table.eduF <- table(df$eduF, df$racePARraceID) prop.eduF <- prop.table(table.eduF, 2) # Mother's Education table.eduM <- table(df$eduM, df$racePARraceID) prop.eduM <- prop.table(table.eduM, 2) # Family Income table.inc <- table(df$incomecat, df$racePARraceID) prop.inc <- prop.table(table.inc, 2) ## Figure 1 pdf(file="fig1.pdf", height=4.5, width=10) par(mfrow=c(1,3), las=1, mar=c(10.5, 3, 4, 1)) barplot(prop.inc, main="Family Income", col=rep("darkgreen",4), dens=c(0,10,20,40), names.arg=rep("",5)) barplot(prop.eduF, main="Father's Education", col=rep("blue",4), dens=c(0,10,20,40), names.arg=rep("",5)) barplot(prop.eduM, main="Mother's Education", col=rep("blue",4), dens=c(0,10,20,40), names.arg=rep("",5)) par(xpd=NA) # legends tmp <- cnvrt.coords(0.045,0.117, 'tdev')$usr legend(tmp, c("Below $30,000", "$30,000-$59,999", "$60,000-$99,999", "Above $100,000"), col=rep("darkgreen",4), dens=c(0,10,20,30), ncol=2, cex=1.17, pt.cex=1.4) tmp <- cnvrt.coords(0.390,0.117, 'tdev')$usr; legend(tmp, c("HS Degree or Less", "Some College", "College Degree", "Graduate School"), col=rep("blue",4), dens=c(0,10,20,30), ncol=4, cex=1.17, pt.cex=1.4) # x-axis labels LABELS <- c("Monoracial Whites", "Biracial Whites", "Biracial White-Blacks", "Biracial Blacks", "Monoracial Blacks") tmp <- cnvrt.coords(seq(0.075,0.285,length.out=5),0.285, 'tdev')$usr text(tmp, srt=45, adj=1, labels=LABELS, cex=0.70) tmp <- cnvrt.coords(seq(0.415,0.62,length.out=5),0.285, 'tdev')$usr text(tmp, srt=45, adj=1, labels=LABELS, cex=0.70) tmp <- cnvrt.coords(seq(0.750,0.955,length.out=5),0.285, 'tdev')$usr text(tmp, srt=45, adj=1, labels=LABELS, cex=0.70) dev.off() ################# ## FIGURES 2-4 ## ################# # Get predicted probabilities sims.whites <- parLapply( cl=cl, m.whites.matched, Sims, ids=c("wPARwID", "wbPARwID"), female=1, wfabmo=0, region5="Northeast", eduF="HS diploma or less", eduM= "HS diploma or less", incomecat="$30,000-$59,999", religionst="Other Christian", parstat="Parents Together", year="2003" ) sims.blacks <- parLapply( cl=cl, m.blacks.matched, Sims, ids=c("bPARbID", "wbPARbID"), female=1, wfabmo=0, region5="South", eduF="HS diploma or less", eduM= "HS diploma or less", incomecat="$30,000-$59,999", religionst="Other Christian", parstat="Parents Together", year="2003" ) a <- setx(m.blacks.matched[[2]], racePARraceID="bPARbID") b <- setx(m.blacks.matched[[2]], racePARraceID="wbPARbID") foo <- sim(m.blacks.matched[[2]], x = b, 10000) summary(m.blacks.matched[[2]]) sims.mixed.blacks <- parLapply( cl=cl, m.whblk, Sims, ids=c("wbPARwbID", "wbPARbID"), female=1, wfabmo=0, region5="South", eduF="HS diploma or less", eduM= "HS diploma or less", incomecat="less than $30,000", religionst="Baptist", parstat="Parents not together or dead", year="2003" ) sims.mixed.whites <- parLapply( cl=cl, m.whblk, Sims, ids=c("wbPARwbID", "wbPARwID"), female=1, wfabmo=0, region5="Northeast", eduF="HS diploma or less", eduM= "HS diploma or less", incomecat="$30,000-$59,999", religionst="Other Christian", parstat="Parents not together or dead", year="2003" ) # Extract and summarize diff.white <- diff.black <- matrix(NA, nrow=9, ncol=5) diff.mixed <- array(NA, c(9,5,2)) rownames(diff.white) <- rownames(diff.black) <- rownames(diff.mixed) <- paste(dvs) tertiles <- c(0, 1/3, 2/3, 1) quantiles <- c(0.025, 0.05, 0.5, 0.95, 0.975) sims.whites <- list() for(i in c(1:9)){ a <- setx(m.whites.matched[[i]], racePARraceID="wPARwID") b <- setx(m.whites.matched[[i]], racePARraceID="wbPARwID") sims.whites[[i]] <- sim(m.whites.matched[[i]], x = a, x1 = b, 10000) diff.white[i,] <- quantile( rowSums(sims.whites[[i]]$qi$fd[,1:4] %*% diag(tertiles)), quantiles) } sims.blacks <- list() for(i in c(1,3:9)){ a <- setx(m.blacks.matched[[i]], racePARraceID="bPARbID") b <- setx(m.blacks.matched[[i]], racePARraceID="wbPARbID") sims.blacks[[i]] <- sim(m.blacks.matched[[i]], x = a, x1 = b, 10000) diff.black[i,] <- quantile( rowSums(sims.blacks[[i]]$qi$fd[,1:4] %*% diag(tertiles)), quantiles) } for (i in 1:length(dvs)){ diff.white[i,] <- quantile( rowSums(sims.whites[[i]]$qi$fd[,1:4] %*% diag(tertiles)), quantiles) # diff.black[i,] <- quantile( # rowSums(sims.blacks[[i]]$qi$fd[,1:4] %*% diag(tertiles)), quantiles) diff.mixed[i,,1] <- quantile( rowSums(sims.mixed.blacks[[i]]$qi$fd[,1:4] %*% diag(tertiles)), quantiles) diff.mixed[i,,2] <- quantile( rowSums(sims.mixed.whites[[i]]$qi$fd[,1:4] %*% diag(tertiles)), quantiles) } stopCluster(cl) ######## FIGURE 2: EXPLICITLY RACIAL ISSUES ######## pdf(file="fig2.pdf", height=2.75, width=9.75) myPlot(vars=c(1:3), var.names=c("Racism is a \n Major Problem", "Racial \n Understanding ", "Affirmative Action")) dev.off() ######## FIGURE 3: IMPLICITLY RACIAL ISSUES ######## pdf(file="fig3.pdf", height=2.75, width=9.75) myPlot(vars=c(4:6), var.names=c("Criminals' Rights", "Death Penalty", "Gun Control")) dev.off() ######## FIGURE 4: NON-RACIAL ISSUES ######## pdf(file="fig4.pdf", height=2.75, width=9.75) myPlot(vars=c(7,9,8), var.names=c("Abortion Rights", "Married Women \n Remain in Home", "Same-Sex \n Marriage")) dev.off()