First step when working with the CMPS. We need to read it in.

  1. We the data and figure out what format it is in (txt, spss, dta, csv, .RData)

  2. We will be using the code book I have attached it depends on what year you are using it should be labeled CMPS 2022, CMPS 2020 OR CMPS 2016

  3. You can create an R Project here if you’d like in which you will save all your data, scripts, etc.

I prefer to do this although maake sure to have it organized so you know where your R project is

  1. Create a folder for the data and save it there.

  2. Create an R-script for cleaning the data and save it there as well.

  3. Read in the data. #

What is an R Script?

# Header of an R script
###########
# CMPS Intoduction 
#Name here 
#Descritpion of project 
###########

#to make sure our analysis is replicable and that we do not have other variabels that have the same name we will clear our work space. It is like cleaning your desk from your old projects for a new project so nothing from your old project gets in the way. 
#clear workspace
rm(list = ls()) #remove everything in working memory
#this as an analogy allows us to remove everything so we can start. 

#What is working memory? If you look to the right of RStudio you see objects that are loaded into memory on the right. 

# Note that I never attach my data. Because if you have two different data sets and are using the same varaible you may not be sure if you are using the correct variable. 

# load packages 
library(tidyverse) # go ahead and install if you need to with install.packages('tidyverse')
load("~/Downloads/Pols 308/CMPS 2020 contextual full adult sample weighted R.RData")

The most common step after you load the data you write View to observe the title of the data and the first couple of observations.You can also use the function names() to get all the names of the variables. The glimpse function is from the dplyr() package and lets you see the types of variables that you have in your dataset.

 load("~/Downloads/Pols 308/CMPS 2020 contextual full adult sample weighted R.RData")
CMPS_2020<-df.merged


#data set only for Latinos 

#Regardless of what language you took this survey, how often do you speak Spanish in your household or with friends and family? 
CMPS_2020$spanish_speaking_frequency<-CMPS_2020$Q816

#Record language of survey Spanish .............................................................................. 2
CMPS_2020$spanish_survey<-ifelse(CMPS_2020$S1==2, 1, 0)

CMPS_2020$edu<-CMPS_2020$S13

#S13. What is the highest level of education you completed?
#Grades 1-8 ......................................................................... 1
#Some High School, but did not graduate ......................... 2
#High School graduate or GED ........................................... 3
#Some college ..................................................................... 4
#Associates, 2-year degree ................................................. 5
#Bachelors, 4-year degree .................................................. 6
#Post-graduate degree ....................................................... 7


CMPS_2020$income<-CMPS_2020$Q813
# was your total combined household income in 2020 before taxes. This question is completely confidential and just used to help classify the responses, but it is very important to the research.
#Less than $20,000………………..1
#$20,000 to $29,999………………..2
#$30,000 to $39,999………………..3
#$40,000 to $49,999………………..4
##$50,000 to $59,999………………..5
#$60,000 to $69,999………………..6
#$70,000 to $79,999………………..7
#$80,000 to $89,999………………..8
#$90,000 to $99,999………………..9
#$100,000 to $149,999………………..10
#$150,000 to $199,999………………..11
#$200,000 or more………………..12

#Gender, 
#S3b. What is your gender?
#Man ................................................................................... 1
#Woman .............................................................................. 2
#Non-binary ........................................................................ 3
#Something else [Specify] ................................................... 4
CMPS_2020$man<-ifelse(CMPS_2020$S3b
 ==1, 1, 0)

CMPS_2020$woman<-ifelse(CMPS_2020$S3b
 ==2, 1, 0)

CMPS_2020$non_binary<-ifelse(CMPS_2020$S3b
 ==3, 1, 0)

CMPS_2020$transgender<-ifelse(CMPS_2020$S3c
 ==1, 1, 0)

 #Q21: Do you consider your party identification to be
CMPS_2020$republican<-ifelse(CMPS_2020$Q21 ==1, 1, 0)
CMPS_2020$democrat<-ifelse(CMPS_2020$Q21 ==2, 1, 0)
CMPS_2020$independent<-ifelse(CMPS_2020$Q21 ==3, 1, 0)

CMPS_2020$ideology<-(CMPS_2020$Q43)
#43. When it comes to politics, do you think of yourself as liberal, moderate, or conservative?
#Very Liberal ....................................................................... 1
#Somewhat Liberal ............................................................. 2
#Moderate .......................................................................... 3
#Somewhat Conservative ................................................... 4
#Very Conservative ............................................................. 5
#None of these ................................................................... 6

#controls # remove NA
CMPS_2020 = filter(CMPS_2020, income != 99)
CMPS_2020 = filter(CMPS_2020, ideology!= 6)


CMPS_2020$street_race<-CMPS_2020$Q801
#801. If you were walking down the street, what race do you think other Americans who do not know you personally would assume you were based on what you look like? [ROTATE LIST]
#White, not Hispanic .......................................................... 1
#Black .................................................................................. 2
#Latino or Hispanic ............................................................. 3
#Asian American ................................................................. 4
#Middle Eastern/Arab ......................................................... 5
#American Indian or Alaskan Native .................................. 6
#Native Hawaiian ................................................................ 7
#Pacific Islander (not Hawaiian) ......................................... 8
#Other: SPECIFY .................................................................. 7

#afro latinos 802
CMPS_2020$afro_terms<-CMPS_2020$Q802
#802. [AF] There are many different ways to describe race among Caribbean and Latino populations. What is
#the category that you would use to best describe your racial appearance?
#White................................................................................. 1
##Black .................................................................................. 2
#Trigueño ............................................................................ 3
#Mulato/Mestizo ................................................................ 4
#Indio .................................................................................. 5
#Jabao ................................................................................. 6
#Brown-skinned .................................................................. 7
#Moreno ............................................................................. 8
#Other [SPECIFY] ................................................................. 9
  # census 803
CMPS_2020$census<-CMPS_2020$Q803
CMPS_2020$census_white_latino<- ifelse(CMPS_2020$census==1, 1, 0)
CMPS_2020$census_some_other_latino<- ifelse(CMPS_2020$census==6, 1, 0)

#803. Which racial category did you choose on the 2020 U.S. Census?
#White................................................................................. 1
#Black or African American................................................. 2
#American Indian or Alaska Native..................................... 3
#Native Hawaiian or Pacific Islander .................................. 4
#Asian .................................................................................. 5
#Some Other Race .............................................................. 6
#Did not complete 2020 Census.............................................7



CMPS_2020$colorblind<-((CMPS_2020$Q217r1+CMPS_2020$Q217r2)-2)
table(CMPS_2020$colorblind)
## 
##    0    1    2    3    4    5    6    7    8    9   10 
##  394  394  708 1113 2511 6300 2063  694  308  126  155
CMPS_2020$colorblind<-as.factor(
  CMPS_2020$colorblind)

CMPS_2020$rr<-((CMPS_2020$Q213r1+CMPS_2020$Q213r2+CMPS_2020$Q213r3+CMPS_2020$Q213r4)-4)
CMPS_2020$rr<-as.factor(CMPS_2020$rr)
table(CMPS_2020$rr)
## 
##    0    1    2    3    4    5    6    7    8    9   10   11   12   13   14   15 
##  294  133  328  423  929 1025 1727 2226 4845 1484  784  259  193   56   29    8 
##   16 
##   23
#
#14. In the election for president, [IF Q12=1 or 2 “did you vote for”; all others: “even if you did not vote, did you support”; if age=16-17 “even though you’re not old enough to vote, did you support” [ROTATE] {the Republican ticket, Donald Trump and Mike Pence} or {the Democratic ticket, Joe Biden and Kamala Harris}
CMPS_2020$trump_rep<- ifelse(CMPS_2020$Q14==1, 1, 0)
CMPS_2020$biden_dem<- ifelse(CMPS_2020$Q14==2, 1, 0)


#61. What primary religion, if any, did your family practice or follow when you were raised?
#Catholic ............................................................................. 1
CMPS_2020$catholic<-ifelse(CMPS_2020$Q61==1, 1, 0)

#59.generally speaking, about how often did you used to participate in worship services or religious rituals with others?
CMPS_2020$religiosity<-CMPS_2020$Q59
#reg voter 

CMPS_2020$registered<-ifelse(CMPS_2020$S6==1, 1, 0)
#pol interest 
CMPS_2020$int_pol<-CMPS_2020$Q29

CMPS_2020$disc_police<-CMPS_2020$Q281r2
CMPS_2020$disc_immigration_enforcement<-CMPS_2020$Q281r3
CMPS_2020$disc_work<-CMPS_2020$Q281r6
CMPS_2020$disc_entertainment<-CMPS_2020$Q281r5
CMPS_2020$disc_store<-CMPS_2020$Q281r6
CMPS_2020$disc_others<-CMPS_2020$Q281r7
CMPS_2020$disc_other<-CMPS_2020$Q281r8
CMPS_2020$disc_none<-CMPS_2020$Q281r9


#628. [IF Q627=1] In your opinion, were you unfairly treated because of your [Check all that apply]

CMPS_2020$disc_imm_race_ethnic<-CMPS_2020$Q629r1

#Racial background or ethnicity……1
CMPS_2020$disc_imm_skin<-CMPS_2020$Q629r2

#Skin color……2
CMPS_2020$disc_imm_gender<-CMPS_2020$Q629r4
#Gender……3
#Sexuality or sexual orientation……4 
CMPS_2020$disc_imm_sexuality<-CMPS_2020$Q629r4

#Immigration status……5
CMPS_2020$disc_imm_status<-CMPS_2020$Q629r5

#Accent, regardless of whether or not you have an accent……7
CMPS_2020$disc_imm_accent<-CMPS_2020$Q629r7
#k an average month, do any of the following every happen to you

#629. People ever act as if you don’t speak English
CMPS_2020$imm_noenglish<-CMPS_2020$Q630_Q632r1

#630. People assume that you are good at math or science
CMPS_2020$imm_math<-CMPS_2020$Q630_Q632r2

#631. People assume that you are not American
CMPS_2020$imm_notamerican<-CMPS_2020$Q630_Q632r3

#Yes ..................................................................................... 1


#When you go to vote for a (national/state/local OR partisan/nonpartisan) election, how important are the following to you in a candidate: [

CMPS_2020$desc_racial_voting<-CMPS_2020$Q316r1
#316............. Their racial background is the same as yours
#Very unimportant 1
#Somewhat unimportant 2
#Neither important/unimportant 3
#Somewhat important 4
#Very important  5 

CMPS_2020$desc_gender_voting<-CMPS_2020$Q316r2

#317............. Their gender is the same as yours
#Very unimportant 1
#Somewhat unimportant 2
#Neither important/unimportant 3
#Somewhat important 4
#Very important  5 

CMPS_2020$substantive_views_voting<-CMPS_2020$Q316r4

#319............. They share the same values as you do
#Very unimportant 1
#Somewhat unimportant 2
#Neither important/unimportant 3
#Somewhat important 4
#Very important  5 
CMPS_2020$substantive_issues_voting<-CMPS_2020$Q316r5

#320............. They believe the same issues are as important as you
#Very unimportant 1
#Somewhat unimportant 2
#Neither important/unimportant 3
#Somewhat important 4
#Very important  5 
CMPS_2020$substantive_stances_voting<-CMPS_2020$Q316r6

#321............. They take the same stances on most of the same political issues
#Very unimportant 1
#Somewhat unimportant 2
#Neither important/unimportant 3
#Somewhat important 4
#Very important  5 
CMPS_2020$sameparty_voting<-CMPS_2020$Q316r7
#322............. They are in the same party as you
#Very unimportant 1
#Somewhat unimportant 2
#Neither important/unimportant 3
#Somewhat important 4
#Very important  5 

#Which of the following traits do you prefer in a candidate for office you might support [Grid, random]
CMPS_2020$desc_race_important<-CMPS_2020$Q494_Q503r1
#494. Shares my race
#not prefer .................................................................... 1
#Prefer moderately............................................................. 2
#Prefer a great deal ............................................................ 3
CMPS_2020$desc_gender_important<-CMPS_2020$Q494_Q503r2

#495. Shares my gender
#not prefer .................................................................... 1
#Prefer moderately............................................................. 2
#Prefer a great deal ............................................................ 3


#551. What happens to Black people will have...
#Nothing to do with what happens in my life............................................... 1
#Only a little to do with what happens in my life ......................................... 2
#Something to do with what happens in my life .......................................... 3
#A lot to do with what happens in my life .................................................... 4
#A huge amount to do with what happens in my life................................... 5
CMPS_2020$black_linked_fate<-CMPS_2020$Q551_Q559r1
#552. What happens to Hispanic people will have..

#Nothing to do with what happens in my life............................................... 1
#Only a little to do with what happens in my life ......................................... 2
#Something to do with what happens in my life .......................................... 3
#A lot to do with what happens in my life .................................................... 4
#A huge amount to do with what happens in my life................................... 5
CMPS_2020$hispanic_linked_fate<-CMPS_2020$Q551_Q559r2
#553. What happens to LGBTQ people will have...

#Nothing to do with what happens in my life............................................... 1
#Only a little to do with what happens in my life ......................................... 2
#Something to do with what happens in my life .......................................... 3
#A lot to do with what happens in my life .................................................... 4
#A huge amount to do with what happens in my life................................... 5
CMPS_2020$lgbtq_linked_fate<-CMPS_2020$Q551_Q559r3
#554. What happens to White people will have...

#Nothing to do with what happens in my life............................................... 1
#Only a little to do with what happens in my life ......................................... 2
#Something to do with what happens in my life .......................................... 3
#A lot to do with what happens in my life .................................................... 4
#A huge amount to do with what happens in my life................................... 5
#Nothing to do with what happens in my life............................................... 1
#Only a little to do with what happens in my life ......................................... 2
#Something to do with what happens in my life .......................................... 3
#A lot to do with what happens in my life .................................................... 4
#A huge amount to do with what happens in my life................................... 5
#Nothing to do with what happens in my life............................................... 1
#Only a little to do with what happens in my life ......................................... 2
#Something to do with what happens in my life .......................................... 3
#A lot to do with what happens in my life .................................................... 4
#A huge amount to do with what happens in my life................................... 5
CMPS_2020$white_linked_fate<-CMPS_2020$Q551_Q559r4
#555. What happens to Asian people will have...

#Nothing to do with what happens in my life............................................... 1
#Only a little to do with what happens in my life ......................................... 2
#Something to do with what happens in my life .......................................... 3
#A lot to do with what happens in my life .................................................... 4
#A huge amount to do with what happens in my life................................... 5
CMPS_2020$asian_linked_fate<-CMPS_2020$Q551_Q559r5
#557. What happens to Native or indigenous people will have.
#Nothing to do with what happens in my life............................................... 1
#Only a little to do with what happens in my life ......................................... 2
#Something to do with what happens in my life .......................................... 3
#A lot to do with what happens in my life .................................................... 4
#A huge amount to do with what happens in my life................................... 5
CMPS_2020$native_linked_fate<-CMPS_2020$Q551_Q559r7
#How would you rate your feelings toward each of the following groups on a scale from 0 - 100 where 0 means
#very cold, and 100 means very warm? [Grid with Widget for each group] 308..Undocumented immigrants
CMPS_2020$undoc_feel <-CMPS_2020$Q308r1

cmps_white<-subset(CMPS_2020, S2_Race_Prime  ==  1)