Analyzing Experimental Data

##Initial Data Work

First assessment of the data structure to understand what variables are numerical, factor, character, etc.

#Import Data
library(haven)
experimental_data <- read_sav("grad_experiments23_set1_May+3,+2023_10.56.sav")


#Removing the row with data from the person who opted out of the survey, the person who declined to identify gender, and those that chose independent when asked for lean
experimental_data_1 <- experimental_data %>% 
  slice(-c(48,130,131,135,152,156,192,211))

#Variable Review
names(experimental_data_1)
##  [1] "StartDate"                  "EndDate"                   
##  [3] "Status"                     "IPAddress"                 
##  [5] "Progress"                   "Duration__in_seconds_"     
##  [7] "Finished"                   "RecordedDate"              
##  [9] "ResponseId"                 "RecipientLastName"         
## [11] "RecipientFirstName"         "RecipientEmail"            
## [13] "ExternalReference"          "LocationLatitude"          
## [15] "LocationLongitude"          "DistributionChannel"       
## [17] "UserLanguage"               "Q_RecaptchaScore"          
## [19] "Q_RelevantIDDuplicate"      "Q_RelevantIDDuplicateScore"
## [21] "Q_RelevantIDFraudScore"     "Q_RelevantIDLastStartDate" 
## [23] "Q1.1"                       "Q2.1"                      
## [25] "Q2.2"                       "Q2.4"                      
## [27] "Q2.5_1"                     "Q2.5_2"                    
## [29] "Q2.5_3"                     "Q2.5_4"                    
## [31] "Q2.5_5"                     "Q2.5_DO_1"                 
## [33] "Q2.5_DO_2"                  "Q2.5_DO_3"                 
## [35] "Q2.5_DO_4"                  "Q2.5_DO_5"                 
## [37] "Q3.11_1"                    "Q3.11_2"                   
## [39] "Q3.11_3"                    "Q3.11_4"                   
## [41] "Q3.11_5"                    "Q3.11_DO_1"                
## [43] "Q3.11_DO_2"                 "Q3.11_DO_3"                
## [45] "Q3.11_DO_4"                 "Q3.11_DO_5"                
## [47] "Q3.16_4"                    "Q3.17_14"                  
## [49] "Q4.4_1"                     "Q4.5_1"                    
## [51] "Q5.5"                       "Q5.6"                      
## [53] "Q6.1_1"                     "Q6.1_2"                    
## [55] "Q6.1_3"                     "Q6.1_4"                    
## [57] "Q6.1_5"                     "Q6.1_6"                    
## [59] "Q6.1_7"                     "Q6.1_8"                    
## [61] "Q6.1_9"                     "Q6.2"                      
## [63] "Q6.3"                       "Q6.4_1"                    
## [65] "Q4.6"                       "Q4.7"                      
## [67] "Random_ID"                  "kristina_DO_Q3.9"          
## [69] "kristina_DO_Q3.8"           "kristina_DO_Q3.7"          
## [71] "kristina_DO_Q3.6"           "kristina_DO_Q3.5"          
## [73] "kristina_DO_Q3.4"           "kristina_DO_Q3.3"          
## [75] "kristina_DO_Q3.2"           "kristina_DO_Q3.1"          
## [77] "matthew_DO_Q4.3"            "matthew_DO_Q4.2"           
## [79] "matthew_DO_Q4.1"            "justin_DO_Q5.4"            
## [81] "justin_DO_Q5.3"             "justin_DO_Q5.2"            
## [83] "justin_DO_Q5.1"
#Unweighted summary values for numeric variables
skim(experimental_data_1)
Data summary
Name experimental_data_1
Number of rows 276
Number of columns 83
_______________________
Column type frequency:
character 12
numeric 67
POSIXct 4
________________________
Group variables None

Variable type: character

skim_variable n_missing complete_rate min max empty n_unique whitespace
IPAddress 0 1 11 15 0 276 0
ResponseId 0 1 17 17 0 276 0
RecipientLastName 0 1 0 0 276 1 0
RecipientFirstName 0 1 0 0 276 1 0
RecipientEmail 0 1 0 0 276 1 0
ExternalReference 0 1 0 0 276 1 0
LocationLatitude 0 1 5 7 0 82 0
LocationLongitude 0 1 6 9 0 82 0
DistributionChannel 0 1 9 9 0 1 0
UserLanguage 0 1 2 2 0 1 0
Q_RelevantIDDuplicate 0 1 0 0 276 1 0
Random_ID 0 1 5 5 0 275 0

Variable type: numeric

skim_variable n_missing complete_rate mean sd p0 p25 p50 p75 p100 hist
Status 0 1.00 0.00 0.00 0.0 0.00 0.0 0.00 0 ▁▁▇▁▁
Progress 0 1.00 100.00 0.00 100.0 100.00 100.0 100.00 100 ▁▁▇▁▁
Duration_in_seconds 0 1.00 383.22 793.08 66.0 128.00 202.5 355.50 11214 ▇▁▁▁▁
Finished 0 1.00 1.00 0.00 1.0 1.00 1.0 1.00 1 ▁▁▇▁▁
Q_RecaptchaScore 10 0.96 0.94 0.13 0.1 0.90 1.0 1.00 1 ▁▁▁▁▇
Q_RelevantIDDuplicateScore 0 1.00 0.00 0.00 0.0 0.00 0.0 0.00 0 ▁▁▇▁▁
Q_RelevantIDFraudScore 0 1.00 26.41 25.06 0.0 0.00 30.0 30.00 135 ▇▇▁▁▁
Q1.1 0 1.00 1.00 0.00 1.0 1.00 1.0 1.00 1 ▁▁▇▁▁
Q2.1 0 1.00 1.75 0.74 1.0 1.00 2.0 2.00 3 ▇▁▇▁▃
Q2.2 49 0.82 1.10 0.30 1.0 1.00 1.0 1.00 2 ▇▁▁▁▁
Q2.4 227 0.18 1.59 0.50 1.0 1.00 2.0 2.00 2 ▆▁▁▁▇
Q2.5_1 0 1.00 2.21 1.08 1.0 2.00 2.0 3.00 5 ▅▇▂▂▁
Q2.5_2 0 1.00 2.12 1.06 1.0 1.00 2.0 2.25 5 ▅▇▂▁▁
Q2.5_3 1 1.00 2.36 1.12 1.0 2.00 2.0 3.00 5 ▃▇▂▂▁
Q2.5_4 1 1.00 2.10 1.09 1.0 1.00 2.0 2.50 5 ▆▇▂▂▁
Q2.5_5 0 1.00 2.02 1.02 1.0 1.00 2.0 2.00 5 ▅▇▂▁▁
Q2.5_DO_1 0 1.00 2.96 1.39 1.0 2.00 3.0 4.00 5 ▆▇▇▆▆
Q2.5_DO_2 0 1.00 3.06 1.44 1.0 2.00 3.0 4.00 5 ▇▆▇▇▇
Q2.5_DO_3 0 1.00 2.86 1.46 1.0 1.75 3.0 4.00 5 ▇▆▆▆▆
Q2.5_DO_4 0 1.00 3.00 1.41 1.0 2.00 3.0 4.00 5 ▆▇▆▆▇
Q2.5_DO_5 0 1.00 3.13 1.37 1.0 2.00 3.0 4.00 5 ▆▆▇▇▆
Q3.11_1 0 1.00 2.29 1.02 1.0 2.00 2.0 3.00 5 ▃▇▃▂▁
Q3.11_2 0 1.00 2.63 1.22 1.0 2.00 2.0 3.00 5 ▃▇▅▃▂
Q3.11_3 0 1.00 2.08 1.01 1.0 1.00 2.0 3.00 5 ▆▇▃▁▁
Q3.11_4 0 1.00 2.20 1.07 1.0 1.00 2.0 3.00 5 ▅▇▃▂▁
Q3.11_5 0 1.00 2.15 1.11 1.0 1.00 2.0 3.00 5 ▆▇▃▂▁
Q3.11_DO_1 0 1.00 2.97 1.45 1.0 2.00 3.0 4.00 5 ▇▇▇▆▇
Q3.11_DO_2 0 1.00 2.86 1.32 1.0 2.00 3.0 4.00 5 ▆▇▇▆▅
Q3.11_DO_3 0 1.00 3.07 1.43 1.0 2.00 3.0 4.00 5 ▇▇▇▇▇
Q3.11_DO_4 0 1.00 3.10 1.47 1.0 2.00 3.0 4.00 5 ▇▆▆▇▇
Q3.11_DO_5 0 1.00 3.01 1.40 1.0 2.00 3.0 4.00 5 ▆▇▆▇▆
Q3.16_4 0 1.00 73.96 17.39 14.0 65.00 76.0 86.00 100 ▁▁▅▇▇
Q3.17_14 0 1.00 75.39 17.93 0.0 67.75 77.5 87.00 100 ▁▁▂▇▇
Q4.4_1 0 1.00 2.07 0.92 1.0 1.00 2.0 2.00 5 ▃▇▂▁▁
Q4.5_1 1 1.00 2.19 0.92 1.0 2.00 2.0 2.50 5 ▂▇▂▁▁
Q5.5 0 1.00 1.93 0.83 1.0 1.00 2.0 2.00 5 ▅▇▁▁▁
Q5.6 0 1.00 2.15 0.87 1.0 2.00 2.0 3.00 5 ▅▇▅▁▁
Q6.1_1 258 0.07 1.00 0.00 1.0 1.00 1.0 1.00 1 ▁▁▇▁▁
Q6.1_2 265 0.04 1.00 0.00 1.0 1.00 1.0 1.00 1 ▁▁▇▁▁
Q6.1_3 264 0.04 1.00 0.00 1.0 1.00 1.0 1.00 1 ▁▁▇▁▁
Q6.1_4 267 0.03 1.00 0.00 1.0 1.00 1.0 1.00 1 ▁▁▇▁▁
Q6.1_5 271 0.02 1.00 0.00 1.0 1.00 1.0 1.00 1 ▁▁▇▁▁
Q6.1_6 271 0.02 1.00 0.00 1.0 1.00 1.0 1.00 1 ▁▁▇▁▁
Q6.1_7 29 0.89 1.00 0.00 1.0 1.00 1.0 1.00 1 ▁▁▇▁▁
Q6.1_8 271 0.02 1.00 0.00 1.0 1.00 1.0 1.00 1 ▁▁▇▁▁
Q6.1_9 270 0.02 1.00 0.00 1.0 1.00 1.0 1.00 1 ▁▁▇▁▁
Q6.2 0 1.00 1.56 0.50 1.0 1.00 2.0 2.00 2 ▆▁▁▁▇
Q6.3 1 1.00 2.58 1.13 1.0 1.00 3.0 3.00 4 ▆▁▁▇▅
Q6.4_1 1 1.00 17.00 8.19 2.0 13.00 15.0 18.00 52 ▂▇▁▁▁
Q4.6 0 1.00 1.67 0.48 1.0 1.00 2.0 2.00 3 ▃▁▇▁▁
Q4.7 2 0.99 1.82 0.39 1.0 2.00 2.0 2.00 2 ▂▁▁▁▇
kristina_DO_Q3.9 241 0.13 2.00 0.00 2.0 2.00 2.0 2.00 2 ▁▁▇▁▁
kristina_DO_Q3.8 244 0.12 2.00 0.00 2.0 2.00 2.0 2.00 2 ▁▁▇▁▁
kristina_DO_Q3.7 241 0.13 2.00 0.00 2.0 2.00 2.0 2.00 2 ▁▁▇▁▁
kristina_DO_Q3.6 242 0.12 2.00 0.00 2.0 2.00 2.0 2.00 2 ▁▁▇▁▁
kristina_DO_Q3.5 240 0.13 2.00 0.00 2.0 2.00 2.0 2.00 2 ▁▁▇▁▁
kristina_DO_Q3.4 241 0.13 2.00 0.00 2.0 2.00 2.0 2.00 2 ▁▁▇▁▁
kristina_DO_Q3.3 241 0.13 2.00 0.00 2.0 2.00 2.0 2.00 2 ▁▁▇▁▁
kristina_DO_Q3.2 242 0.12 2.00 0.00 2.0 2.00 2.0 2.00 2 ▁▁▇▁▁
kristina_DO_Q3.1 0 1.00 1.00 0.00 1.0 1.00 1.0 1.00 1 ▁▁▇▁▁
matthew_DO_Q4.3 136 0.51 2.00 0.00 2.0 2.00 2.0 2.00 2 ▁▁▇▁▁
matthew_DO_Q4.2 140 0.49 2.00 0.00 2.0 2.00 2.0 2.00 2 ▁▁▇▁▁
matthew_DO_Q4.1 0 1.00 1.00 0.00 1.0 1.00 1.0 1.00 1 ▁▁▇▁▁
justin_DO_Q5.4 208 0.25 1.00 0.00 1.0 1.00 1.0 1.00 1 ▁▁▇▁▁
justin_DO_Q5.3 210 0.24 1.00 0.00 1.0 1.00 1.0 1.00 1 ▁▁▇▁▁
justin_DO_Q5.2 212 0.23 1.00 0.00 1.0 1.00 1.0 1.00 1 ▁▁▇▁▁
justin_DO_Q5.1 198 0.28 1.00 0.00 1.0 1.00 1.0 1.00 1 ▁▁▇▁▁

Variable type: POSIXct

skim_variable n_missing complete_rate min max median n_unique
StartDate 0 1 2023-05-03 05:37:44 2023-05-03 08:18:35 2023-05-03 05:48:44 260
EndDate 0 1 2023-05-03 05:40:07 2023-05-03 08:58:58 2023-05-03 05:55:46 267
RecordedDate 0 1 2023-05-03 05:40:08 2023-05-03 08:58:59 2023-05-03 05:55:46 262
Q_RelevantIDLastStartDate 0 1 1582-10-14 00:00:00 1582-10-14 00:00:00 1582-10-14 00:00:00 1
#This runs a frequency analysis on values in the variables of interest (Foreign Policy and Terrorism)
freq(experimental_data_1$Q3.11_1) #foreign policy 

## How qualified do you believe the candidate is on the following issues? - Foreign Policy 
##       Frequency Percent
## 1            58  21.014
## 2           127  46.014
## 3            55  19.928
## 4            25   9.058
## 5            11   3.986
## Total       276 100.000
freq(experimental_data_1$Q3.11_2) #terrorism

## How qualified do you believe the candidate is on the following issues? - Terrorism 
##       Frequency Percent
## 1            47   17.03
## 2           103   37.32
## 3            58   21.01
## 4            40   14.49
## 5            28   10.14
## Total       276  100.00
attributes(experimental_data_1$Q3.11_1) #value labels for DV-Foreign Policy
## $label
## [1] "How qualified do you believe the candidate is on the following issues? - Foreign Policy"
## 
## $format.spss
## [1] "F40.0"
## 
## $display_width
## [1] 5
## 
## $labels
##     Highly Qualified            Qualified   Somewhat Qualified 
##                    1                    2                    3 
##   Not Very Qualified Not At All Qualified 
##                    4                    5 
## 
## $class
## [1] "haven_labelled" "vctrs_vctr"     "double"
attributes(experimental_data_1$Q3.11_2) #value labels for DV-Terrorism
## $label
## [1] "How qualified do you believe the candidate is on the following issues? - Terrorism"
## 
## $format.spss
## [1] "F40.0"
## 
## $display_width
## [1] 5
## 
## $labels
##     Highly Qualified            Qualified   Somewhat Qualified 
##                    1                    2                    3 
##   Not Very Qualified Not At All Qualified 
##                    4                    5 
## 
## $class
## [1] "haven_labelled" "vctrs_vctr"     "double"
class(experimental_data_1$Q3.11_1) #variable type for DV-Foreign Policy
## [1] "haven_labelled" "vctrs_vctr"     "double"
class(experimental_data_1$Q3.11_2) #variable type for DV-Terrorism
## [1] "haven_labelled" "vctrs_vctr"     "double"
summary(experimental_data_1$Q3.11_1) #central tendencies for DV-Foreign Policy
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    1.00    2.00    2.00    2.29    3.00    5.00
summary(experimental_data_1$Q3.11_2) #central tendencies for DV-Terrorism
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   1.000   2.000   2.000   2.634   3.000   5.000

Transforming variables as needed

#Specifically transforming the variables I need for my analysis

experimental_data_1$age <-  as.numeric(experimental_data_1$Q6.4_1)

#Taking the party data and combining self-identified party members with leaners
experimental_data_1$polparty <- as.numeric(experimental_data_1$Q2.1)
experimental_data_1$leaner <- as.numeric(experimental_data_1$Q2.4)
experimental_data_1 <- experimental_data_1 %>% 
  mutate(party = case_when(
    polparty==2 ~ "Republican",
    polparty==1 ~ "Democrat",
    leaner==1 ~ "Democrat",
    leaner==2 ~ "Republican"
  ))

experimental_data_1$democrat <- ifelse(experimental_data_1$party == "Democrat", 1, 0)

experimental_data_1$republican <- ifelse(experimental_data_1$party == "Republican", 1, 0)

#Checking variable attributes for gender data question
attributes(experimental_data_1$Q6.2)
## $label
## [1] "How do you typically describe yourself when it comes to your gender?"
## 
## $format.spss
## [1] "F40.0"
## 
## $display_width
## [1] 5
## 
## $labels
##                       Male                     Female 
##                          1                          2 
##                 Non-binary                Transgender 
##                          3                          4 
## Identify in some other way       Prefer not to answer 
##                          5                          6 
## 
## $class
## [1] "haven_labelled" "vctrs_vctr"     "double"
#Creating easier to work with gender variables
experimental_data_1$gender <- as.numeric(experimental_data_1$Q6.2)
experimental_data_1$female <- ifelse(experimental_data_1$gender == "2", 1, 0)
experimental_data_1$male <- ifelse(experimental_data_1$gender == "1", 1, 0)

#Taking the gender data and creating variables
experimental_data_1 <- experimental_data_1 %>% 
  mutate(Gender = case_when(
    gender==2 ~ "Female",
    gender==1 ~ "Male"
  ))

experimental_data_1$pt_guns <- as.numeric(experimental_data_1$Q2.5_1) #Creates Pre-test gun law evaluation

experimental_data_1$pt_climate <- as.numeric(experimental_data_1$Q2.5_2) #Creates Pre-test climate change evaluation

experimental_data_1$pt_militarization <- as.numeric(experimental_data_1$Q2.5_3) #Creates Pre-test police militarization evaluation

experimental_data_1$pt_guns_order <- as.numeric(experimental_data_1$Q2.5_DO_1) #Indicates where in 5-question pretest this question was viewed

experimental_data_1$pt_climate_order <- as.numeric(experimental_data_1$Q2.5_DO_2) #Indicates where in 5-question pretest this question was viewed

experimental_data_1$pt_militarization_order <- as.numeric(experimental_data_1$Q2.5_DO_3) #Indicates where in 5-question pretest this question was viewed

#Taking the random treatments and assigning a group label
experimental_data_1 <-  experimental_data_1 %>% 
  mutate(group = case_when(
    kristina_DO_Q3.2==2 ~ "F,C,D",
    kristina_DO_Q3.3==2 ~ "F,C,R",
    kristina_DO_Q3.4==2 ~ "F,V,D",
    kristina_DO_Q3.5==2 ~ "F,V,R",
    kristina_DO_Q3.6==2 ~ "M,C,D",
    kristina_DO_Q3.7==2 ~ "M,C,R",
    kristina_DO_Q3.8==2 ~ "M,V,D",
    kristina_DO_Q3.9==2 ~ "M,V,R",
  ))

#Taking the random treatments and assigning a numeric group label
experimental_data_1 <-  experimental_data_1 %>% 
  mutate(group_number = case_when(
    kristina_DO_Q3.2==2 ~ "1",
    kristina_DO_Q3.3==2 ~ "2",
    kristina_DO_Q3.4==2 ~ "3",
    kristina_DO_Q3.5==2 ~ "4",
    kristina_DO_Q3.6==2 ~ "5",
    kristina_DO_Q3.7==2 ~ "6",
    kristina_DO_Q3.8==2 ~ "7",
    kristina_DO_Q3.9==2 ~ "8",
  ))

#Recoding the treatment groups as in-group for political and gender comparisons
experimental_data_1 <-  experimental_data_1 %>% 
  mutate(treatment_dem = case_when(
    kristina_DO_Q3.2==2 ~ "1",
    kristina_DO_Q3.3==2 ~ "0",
    kristina_DO_Q3.4==2 ~ "1",
    kristina_DO_Q3.5==2 ~ "0",
    kristina_DO_Q3.6==2 ~ "1",
    kristina_DO_Q3.7==2 ~ "0",
    kristina_DO_Q3.8==2 ~ "1",
    kristina_DO_Q3.9==2 ~ "0",
  ))

#Recoding the treatment groups as in-group for political and gender comparisons
experimental_data_1 <-  experimental_data_1 %>% 
  mutate(treatment_rep = case_when(
    kristina_DO_Q3.2==2 ~ "0",
    kristina_DO_Q3.3==2 ~ "1",
    kristina_DO_Q3.4==2 ~ "0",
    kristina_DO_Q3.5==2 ~ "1",
    kristina_DO_Q3.6==2 ~ "0",
    kristina_DO_Q3.7==2 ~ "1",
    kristina_DO_Q3.8==2 ~ "0",
    kristina_DO_Q3.9==2 ~ "1",
  ))

#Recoding the treatment groups as in-group for political and gender comparisons
experimental_data_1 <-  experimental_data_1 %>% 
  mutate(treatment_female = case_when(
    kristina_DO_Q3.2==2 ~ "1",
    kristina_DO_Q3.3==2 ~ "1",
    kristina_DO_Q3.4==2 ~ "1",
    kristina_DO_Q3.5==2 ~ "1",
    kristina_DO_Q3.6==2 ~ "0",
    kristina_DO_Q3.7==2 ~ "0",
    kristina_DO_Q3.8==2 ~ "0",
    kristina_DO_Q3.9==2 ~ "0",
  ))

#Recoding the treatment groups as in-group for political and gender comparisons
experimental_data_1 <-  experimental_data_1 %>% 
  mutate(treatment_male = case_when(
    kristina_DO_Q3.2==2 ~ "0",
    kristina_DO_Q3.3==2 ~ "0",
    kristina_DO_Q3.4==2 ~ "0",
    kristina_DO_Q3.5==2 ~ "0",
    kristina_DO_Q3.6==2 ~ "1",
    kristina_DO_Q3.7==2 ~ "1",
    kristina_DO_Q3.8==2 ~ "1",
    kristina_DO_Q3.9==2 ~ "1",
  ))

#Recoding the treatment groups as in-group for veteran vs. civilian comparisons
experimental_data_1 <-  experimental_data_1 %>% 
  mutate(treatment_veteran = case_when(
    kristina_DO_Q3.2==2 ~ "0",
    kristina_DO_Q3.3==2 ~ "0",
    kristina_DO_Q3.4==2 ~ "1",
    kristina_DO_Q3.5==2 ~ "1",
    kristina_DO_Q3.6==2 ~ "0",
    kristina_DO_Q3.7==2 ~ "0",
    kristina_DO_Q3.8==2 ~ "1",
    kristina_DO_Q3.9==2 ~ "1",
  ))

#Recoding the treatment groups as in-group for veteran vs. civilian comparisons
experimental_data_1 <-  experimental_data_1 %>% 
  mutate(treatment_civilian = case_when(
    kristina_DO_Q3.2==2 ~ "1",
    kristina_DO_Q3.3==2 ~ "1",
    kristina_DO_Q3.4==2 ~ "0",
    kristina_DO_Q3.5==2 ~ "0",
    kristina_DO_Q3.6==2 ~ "1",
    kristina_DO_Q3.7==2 ~ "1",
    kristina_DO_Q3.8==2 ~ "0",
    kristina_DO_Q3.9==2 ~ "0",
  ))

#Transforming the Likert scale to foreignpolicy variable increasing in value
experimental_data_1 <-  experimental_data_1 %>% 
  mutate(foreignpolicy = case_when(
    Q3.11_1==1 ~ "5",
    Q3.11_1==2 ~ "4",
    Q3.11_1==3 ~ "3",
    Q3.11_1==4 ~ "2",
    Q3.11_1==5 ~ "1",
  ))

#Transforming the Likert scale to terrorism variable increasing in value
experimental_data_1 <-  experimental_data_1 %>% 
  mutate(terrorism = case_when(
    Q3.11_2==1 ~ "5",
    Q3.11_2==2 ~ "4",
    Q3.11_2==3 ~ "3",
    Q3.11_2==4 ~ "2",
    Q3.11_2==5 ~ "1",
  ))

#Transforming the Likert scale to economy variable increasing in value
experimental_data_1 <-  experimental_data_1 %>% 
  mutate(economy = case_when(
    Q3.11_2==1 ~ "5",
    Q3.11_2==2 ~ "4",
    Q3.11_2==3 ~ "3",
    Q3.11_2==4 ~ "2",
    Q3.11_2==5 ~ "1",
  ))

#Transforming the Likert scale to healthcare variable increasing in value
experimental_data_1 <-  experimental_data_1 %>% 
  mutate(healthcare = case_when(
    Q3.11_2==1 ~ "5",
    Q3.11_2==2 ~ "4",
    Q3.11_2==3 ~ "3",
    Q3.11_2==4 ~ "2",
    Q3.11_2==5 ~ "1",
  ))

#Transforming the Likert scale to education variable increasing in value
experimental_data_1 <-  experimental_data_1 %>% 
  mutate(education = case_when(
    Q3.11_2==1 ~ "5",
    Q3.11_2==2 ~ "4",
    Q3.11_2==3 ~ "3",
    Q3.11_2==4 ~ "2",
    Q3.11_2==5 ~ "1",
  ))

experimental_data_1$foreignpolicy <- as.numeric(experimental_data_1$Q3.11_1)
#Create variable for evaluation of foreign policy competence

experimental_data_1$terrorism <- as.numeric(experimental_data_1$Q3.11_2)
#Create variable for evaluation of terrorism competence

experimental_data_1$economy <- as.numeric(experimental_data_1$Q3.11_3)
#Create variable for evaluation of economy competence

experimental_data_1$healthcare <- as.numeric(experimental_data_1$Q3.11_4)
#Create variable for evaluation of healthcare competence

experimental_data_1$education <- as.numeric(experimental_data_1$Q3.11_5)
#Create variable for evaluation of education competence

experimental_data_1$feeling <- as.numeric(experimental_data_1$Q3.16_4)
#Creates variable for 100 point feeling thermometer for candidate

experimental_data_1$support <- as.numeric(experimental_data_1$Q3.17_14)
#Creates variable for 100 point support scale for candidate

experimental_data_1$weight<-1 #Creates a weight for use in later table creation 

Graphing results of support for education by party support

#Graph results on Education by party of treatment candidate

#Transforming the group to by-party variables
experimental_data_1 <-  experimental_data_1 %>% 
  mutate(group_by_party = case_when(
    group=="F,C,D" ~ "Dem_Candidate",
    group=="F,C,R" ~ "Rep_Candidate",
    group=="F,V,D" ~ "Dem_Candidate",
    group=="F,V,R" ~ "Rep_Candidate",
    group=="M,C,D" ~ "Dem_Candidate",
    group=="M,C,R" ~ "Rep_Candidate",
    group=="M,V,D" ~ "Dem_Candidate",
    group=="M,V,R" ~ "Rep_Candidate"
  ))
#I will create a clean data frame where I can collect my variables of interest

becvar_data <- experimental_data_1[84:116]

#Check the class/attributes of created variables
class(becvar_data$group_number) #variable type group number, which indicates character.
## [1] "character"
#Change variables to numeric
becvar_data$group_number <- as.numeric(becvar_data$group_number)
becvar_data$treatment_dem <- as.numeric(becvar_data$treatment_dem)
becvar_data$treatment_rep <- as.numeric(becvar_data$treatment_rep)
becvar_data$treatment_female <- as.numeric(becvar_data$treatment_female)
becvar_data$treatment_male <- as.numeric(becvar_data$treatment_male)
becvar_data$treatment_veteran <- as.numeric(becvar_data$treatment_veteran)
becvar_data$treatment_civilian <- as.numeric(becvar_data$treatment_civilian)

write_csv(becvar_data, file = "becvar_data.csv")

Descriptive Data

Looking at the central tendencies of the numerical data

#Descriptive statistics allow us to understand our data, which informs our analyses and how we display our results

becvar_data %>%  #This code allows you to summarize a subset of your variables 
  get_summary_stats(     
    female, male, democrat, republican,  # columns to calculate for
    type = "common")  
## # A tibble: 4 × 10
##   variable       n   min   max median   iqr  mean    sd    se    ci
##   <fct>      <dbl> <dbl> <dbl>  <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
## 1 female       276     0     1    1       1 0.562 0.497  0.03 0.059
## 2 male         276     0     1    0       1 0.438 0.497  0.03 0.059
## 3 democrat     276     0     1    0.5     1 0.5   0.501  0.03 0.059
## 4 republican   276     0     1    0.5     1 0.5   0.501  0.03 0.059
freq(becvar_data$group) #This will be our primary IV in this example analysis 

## becvar_data$group 
##       Frequency Percent
## F,C,D        34   12.32
## F,C,R        35   12.68
## F,V,D        35   12.68
## F,V,R        36   13.04
## M,C,D        34   12.32
## M,C,R        35   12.68
## M,V,D        32   11.59
## M,V,R        35   12.68
## Total       276  100.00
freq(becvar_data$gender) #gender

## becvar_data$gender 
##       Frequency Percent
## 1           121   43.84
## 2           155   56.16
## Total       276  100.00
freq(becvar_data$party) #party

## becvar_data$party 
##            Frequency Percent
## Democrat         138      50
## Republican       138      50
## Total            276     100
freq(becvar_data$education) #education

## becvar_data$education 
##       Frequency Percent
## 1            87  31.522
## 2           111  40.217
## 3            43  15.580
## 4            20   7.246
## 5            15   5.435
## Total       276 100.000
freq(becvar_data$age) #age

## becvar_data$age 
##       Frequency  Percent Valid Percent
## 2             1   0.3623        0.3636
## 4             3   1.0870        1.0909
## 5             6   2.1739        2.1818
## 6             3   1.0870        1.0909
## 7             4   1.4493        1.4545
## 8            11   3.9855        4.0000
## 9             5   1.8116        1.8182
## 10            6   2.1739        2.1818
## 12           16   5.7971        5.8182
## 13           41  14.8551       14.9091
## 14            5   1.8116        1.8182
## 15           48  17.3913       17.4545
## 16           23   8.3333        8.3636
## 17           11   3.9855        4.0000
## 18           28  10.1449       10.1818
## 19            6   2.1739        2.1818
## 20            8   2.8986        2.9091
## 21            3   1.0870        1.0909
## 22            1   0.3623        0.3636
## 23            7   2.5362        2.5455
## 24            3   1.0870        1.0909
## 25            3   1.0870        1.0909
## 26            3   1.0870        1.0909
## 27            4   1.4493        1.4545
## 28            2   0.7246        0.7273
## 29            3   1.0870        1.0909
## 30            1   0.3623        0.3636
## 31            2   0.7246        0.7273
## 33            3   1.0870        1.0909
## 34            2   0.7246        0.7273
## 35            1   0.3623        0.3636
## 38            1   0.3623        0.3636
## 42            5   1.8116        1.8182
## 43            2   0.7246        0.7273
## 45            1   0.3623        0.3636
## 47            1   0.3623        0.3636
## 49            1   0.3623        0.3636
## 52            1   0.3623        0.3636
## NA's          1   0.3623              
## Total       276 100.0000      100.0000

##Balance Tests

Conducting balance tests to ensure that our randomization worked. There is a slight indication that the randomization underexposed the treatment for the male/veteran/democratic candidate. This may be because of the one opt-out of the survey, or the elimination of the 6 respondents that did not choose a party lean.

#Balance tests with factor/ordinal variables 
#Calculates chi-square test statistic for unbalance across experimental conditions

chisq.test(table(becvar_data$group, becvar_data$female))
## 
##  Pearson's Chi-squared test
## 
## data:  table(becvar_data$group, becvar_data$female)
## X-squared = 5.7865, df = 7, p-value = 0.5649
chisq.test(table(becvar_data$group, becvar_data$democrat))
## 
##  Pearson's Chi-squared test
## 
## data:  table(becvar_data$group, becvar_data$democrat)
## X-squared = 8.8336, df = 7, p-value = 0.2648
#Visual inspection of gender and party id variables

freq(becvar_data$democrat)

## becvar_data$democrat 
##       Frequency Percent
## 0           138      50
## 1           138      50
## Total       276     100
freq(becvar_data$female)

## becvar_data$female 
##       Frequency Percent
## 0           121   43.84
## 1           155   56.16
## Total       276  100.00
##CrossTable code from 'gmodels' package  
#Calculates both chi-square tests as well as percentages per cell 

CrossTable(becvar_data$female, becvar_data$group, expected = FALSE, chisq=TRUE,  prop.c=TRUE, prop.r=FALSE, prop.t=FALSE, prop.chisq = FALSE)
## 
##  
##    Cell Contents
## |-------------------------|
## |                       N |
## |           N / Col Total |
## |-------------------------|
## 
##  
## Total Observations in Table:  276 
## 
##  
##                    | becvar_data$group 
## becvar_data$female |     F,C,D |     F,C,R |     F,V,D |     F,V,R |     M,C,D |     M,C,R |     M,V,D |     M,V,R | Row Total | 
## -------------------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|
##                  0 |        14 |        14 |        11 |        20 |        14 |        15 |        17 |        16 |       121 | 
##                    |     0.412 |     0.400 |     0.314 |     0.556 |     0.412 |     0.429 |     0.531 |     0.457 |           | 
## -------------------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|
##                  1 |        20 |        21 |        24 |        16 |        20 |        20 |        15 |        19 |       155 | 
##                    |     0.588 |     0.600 |     0.686 |     0.444 |     0.588 |     0.571 |     0.469 |     0.543 |           | 
## -------------------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|
##       Column Total |        34 |        35 |        35 |        36 |        34 |        35 |        32 |        35 |       276 | 
##                    |     0.123 |     0.127 |     0.127 |     0.130 |     0.123 |     0.127 |     0.116 |     0.127 |           | 
## -------------------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|
## 
##  
## Statistics for All Table Factors
## 
## 
## Pearson's Chi-squared test 
## ------------------------------------------------------------
## Chi^2 =  5.786498     d.f. =  7     p =  0.5648885 
## 
## 
## 
CrossTable(becvar_data$democrat, becvar_data$group, expected = FALSE, chisq=TRUE,  prop.c=TRUE, prop.r=FALSE, prop.t=FALSE, prop.chisq = FALSE)
## 
##  
##    Cell Contents
## |-------------------------|
## |                       N |
## |           N / Col Total |
## |-------------------------|
## 
##  
## Total Observations in Table:  276 
## 
##  
##                      | becvar_data$group 
## becvar_data$democrat |     F,C,D |     F,C,R |     F,V,D |     F,V,R |     M,C,D |     M,C,R |     M,V,D |     M,V,R | Row Total | 
## ---------------------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|
##                    0 |        14 |        14 |        21 |        18 |        18 |        14 |        16 |        23 |       138 | 
##                      |     0.412 |     0.400 |     0.600 |     0.500 |     0.529 |     0.400 |     0.500 |     0.657 |           | 
## ---------------------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|
##                    1 |        20 |        21 |        14 |        18 |        16 |        21 |        16 |        12 |       138 | 
##                      |     0.588 |     0.600 |     0.400 |     0.500 |     0.471 |     0.600 |     0.500 |     0.343 |           | 
## ---------------------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|
##         Column Total |        34 |        35 |        35 |        36 |        34 |        35 |        32 |        35 |       276 | 
##                      |     0.123 |     0.127 |     0.127 |     0.130 |     0.123 |     0.127 |     0.116 |     0.127 |           | 
## ---------------------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|-----------|
## 
##  
## Statistics for All Table Factors
## 
## 
## Pearson's Chi-squared test 
## ------------------------------------------------------------
## Chi^2 =  8.833613     d.f. =  7     p =  0.2648238 
## 
## 
## 

##Average Treatment Effect Analysis

Now that we have conducted balance tests and feel confident that the randomization worked as expected, we can start to analyze the average treatment effect (ATE) of exposure to a candidate profile across 8 conditions varying gender, veteran status, and political party of candidate.

All we are looking for is significant differences between the experimental groups on whatever dependent variable of interest we are examining. We do not need control variables with a strictly randomized experimental design.

My DVs are ordinal (with 5 scale points), so I can calculate the ATE using any technique designed for a numerical DV.

To test my established hypotheses, I’ll need to calculate the average treatment effect for exposure to the different candidate profiles on the evaluation of the candidate’s ability to handle foreign policy and terrorism as a member of congress.

#Visual examination of the IV and DV 
freq(becvar_data$group)

## becvar_data$group 
##       Frequency Percent
## F,C,D        34   12.32
## F,C,R        35   12.68
## F,V,D        35   12.68
## F,V,R        36   13.04
## M,C,D        34   12.32
## M,C,R        35   12.68
## M,V,D        32   11.59
## M,V,R        35   12.68
## Total       276  100.00
freq(becvar_data$foreignpolicy)

## becvar_data$foreignpolicy 
##       Frequency Percent
## 1            58  21.014
## 2           127  46.014
## 3            55  19.928
## 4            25   9.058
## 5            11   3.986
## Total       276 100.000
freq(becvar_data$terrorism)

## becvar_data$terrorism 
##       Frequency Percent
## 1            47   17.03
## 2           103   37.32
## 3            58   21.01
## 4            40   14.49
## 5            28   10.14
## Total       276  100.00
freq(becvar_data$support)

## becvar_data$support 
##       Frequency  Percent
## 0             2   0.7246
## 18            2   0.7246
## 25            1   0.3623
## 28            2   0.7246
## 30            1   0.3623
## 32            2   0.7246
## 35            1   0.3623
## 38            1   0.3623
## 39            1   0.3623
## 40            3   1.0870
## 41            1   0.3623
## 43            1   0.3623
## 44            2   0.7246
## 46            2   0.7246
## 47            1   0.3623
## 49            1   0.3623
## 50            2   0.7246
## 51            1   0.3623
## 52            1   0.3623
## 53            1   0.3623
## 54            1   0.3623
## 55            1   0.3623
## 56            2   0.7246
## 57            3   1.0870
## 58            1   0.3623
## 59            2   0.7246
## 60            1   0.3623
## 61            3   1.0870
## 62            1   0.3623
## 63            3   1.0870
## 64            3   1.0870
## 65            9   3.2609
## 66            4   1.4493
## 67            6   2.1739
## 68            5   1.8116
## 69            1   0.3623
## 70           11   3.9855
## 71            7   2.5362
## 72            8   2.8986
## 73            9   3.2609
## 74            9   3.2609
## 75            9   3.2609
## 76            7   2.5362
## 77            3   1.0870
## 78            5   1.8116
## 79            3   1.0870
## 80           10   3.6232
## 81            4   1.4493
## 82           10   3.6232
## 83            7   2.5362
## 84           10   3.6232
## 85            9   3.2609
## 86            9   3.2609
## 87            3   1.0870
## 88            9   3.2609
## 89            2   0.7246
## 90            7   2.5362
## 91            4   1.4493
## 92            4   1.4493
## 93            6   2.1739
## 94            3   1.0870
## 95            3   1.0870
## 96            1   0.3623
## 97            3   1.0870
## 98            1   0.3623
## 99            2   0.7246
## 100          23   8.3333
## Total       276 100.0000
freq(becvar_data$feeling)

## becvar_data$feeling 
##       Frequency  Percent
## 14            1   0.3623
## 18            1   0.3623
## 22            1   0.3623
## 30            2   0.7246
## 32            2   0.7246
## 35            1   0.3623
## 37            2   0.7246
## 38            1   0.3623
## 39            1   0.3623
## 40            2   0.7246
## 42            1   0.3623
## 43            2   0.7246
## 44            1   0.3623
## 45            1   0.3623
## 47            2   0.7246
## 48            1   0.3623
## 49            3   1.0870
## 50            3   1.0870
## 51            3   1.0870
## 53            3   1.0870
## 54            1   0.3623
## 55            9   3.2609
## 56            3   1.0870
## 57            1   0.3623
## 58            1   0.3623
## 59            3   1.0870
## 60            4   1.4493
## 61            3   1.0870
## 62            2   0.7246
## 63            5   1.8116
## 64            2   0.7246
## 65           12   4.3478
## 66            2   0.7246
## 67            4   1.4493
## 68            4   1.4493
## 69            5   1.8116
## 70            7   2.5362
## 71            8   2.8986
## 72            8   2.8986
## 73            3   1.0870
## 74           10   3.6232
## 75            5   1.8116
## 76            6   2.1739
## 77            4   1.4493
## 78            8   2.8986
## 79            7   2.5362
## 80           12   4.3478
## 81            8   2.8986
## 82            5   1.8116
## 83            7   2.5362
## 84            1   0.3623
## 85            6   2.1739
## 86            8   2.8986
## 87            5   1.8116
## 88            7   2.5362
## 89            2   0.7246
## 90            6   2.1739
## 91            7   2.5362
## 92            5   1.8116
## 94            2   0.7246
## 95            4   1.4493
## 96            2   0.7246
## 97            1   0.3623
## 98            2   0.7246
## 99            3   1.0870
## 100          22   7.9710
## Total       276 100.0000
#Descriptive statistical examination of the foreignpolicy DV 
sd(becvar_data$foreignpolicy)
## [1] 1.024804
mean(becvar_data$foreignpolicy)
## [1] 2.289855
#Descriptive statistical examination of the terrorism DV 
sd(becvar_data$terrorism)
## [1] 1.215117
mean(becvar_data$terrorism)
## [1] 2.634058

For the foreign policy and terrorism variables, we see that for both evaluations, the most common choice was “2”, or “Qualified”. The ratings range from “5” (Highly Qualified) to “1” (Not at all Qualified).

Graphing the Average Treatment Evaluation by Party

####Graphical Approach to ATE - Get Average Value by Treatment Assignment 
####Then graph the average value with Confidence Intervals 

std.error <- function(x) sd(x)/sqrt(length(x))

graph_fp_data <- becvar_data %>%
  group_by(group, party) %>%
  dplyr::summarise(
    mean_fp = mean(foreignpolicy),
    sd_fp = sd(foreignpolicy),
    n = as.numeric(n()),
    se_fp = std.error(foreignpolicy),
    ub_fp = mean_fp+(1.96*se_fp), 
    lb_fp = mean_fp-(1.96*se_fp))
## `summarise()` has grouped output by 'group'. You can override using the
## `.groups` argument.
graph_ter_data <- becvar_data %>%
  group_by(group, party) %>%
  dplyr::summarise(
    mean_ter = mean(terrorism),
    sd_ter = sd(terrorism),
    n = as.numeric(n()),
    se_ter = std.error(terrorism),
    ub_ter = mean_ter+(1.96*se_ter), 
    lb_ter = mean_ter-(1.96*se_ter))
## `summarise()` has grouped output by 'group'. You can override using the
## `.groups` argument.
ggplot(graph_fp_data, aes(x=group, y=mean_fp, fill=party)) + 
  theme_classic(base_size = 15) + 
  geom_bar(position=position_dodge(), stat="identity",
           colour="black", # Use black outlines,
           size=.3) +      # Thinner lines
  geom_errorbar(aes(ymin=lb_fp, ymax=ub_fp),
                size=.3,    # Thinner lines
                width=.2,
                position=position_dodge(.9))+
  xlab("Treatment Condition") +
  ylab("Evaluation on Foreign Policy") + 
  ggtitle("") +
  theme(plot.title = element_text(hjust = 0.5)) +
  scale_fill_manual(values=c("grey", "grey32")) +
  scale_y_continuous(breaks=seq(0, 5, 0.5)) # Ticks from 0-5, every 1
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once every 8 hours.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.

ggplot(graph_ter_data, aes(x=group, y=mean_ter, fill=party)) + 
  theme_classic(base_size = 15) + 
  geom_bar(position=position_dodge(), stat="identity",
           colour="black", # Use black outlines,
           size=.3) +      # Thinner lines
  geom_errorbar(aes(ymin=lb_ter, ymax=ub_ter),
                size=.3,    # Thinner lines
                width=.2,
                position=position_dodge(.9))+
  xlab("Treatment Condition") +
  ylab("Evaluation on Terrorism") + 
  ggtitle("") +
  theme(plot.title = element_text(hjust = 0.5)) +
  scale_fill_manual(values=c("grey", "grey32")) +
  scale_y_continuous(breaks=seq(0, 5, 0.5)) # Ticks from 0-5, every .5

Graphing the policy ownership issues by evaluation of groups only (non-DV outcome variables)

####Graphical Approach to ATE - Get Average Value by Treatment Assignment 
####Then graph the average value with Confidence Intervals 

std.error <- function(x) sd(x)/sqrt(length(x))

graph_education_data <- becvar_data %>%
  group_by(group) %>%
  dplyr::summarise(
    mean = mean(education),
    sd = sd(education),
    n = as.numeric(n()),
    se = std.error(education),
    ub = mean+(1.96*se), 
    lb = mean-(1.96*se))

graph_economy_data <- becvar_data %>%
  group_by(group) %>%
  dplyr::summarise(
    mean = mean(economy),
    sd = sd(economy),
    n = as.numeric(n()),
    se = std.error(economy),
    ub = mean+(1.96*se), 
    lb = mean-(1.96*se))

graph_healthcare_data <- becvar_data %>%
  group_by(group) %>%
  dplyr::summarise(
    mean = mean(healthcare),
    sd = sd(healthcare),
    n = as.numeric(n()),
    se = std.error(healthcare),
    ub = mean+(1.96*se), 
    lb = mean-(1.96*se))

ggplot(graph_education_data, aes(x=group, y=mean)) + 
  theme_classic(base_size = 15) + 
  geom_bar(position=position_dodge(), stat="identity",
           colour="black", # Use black outlines,
           size=.3) +      # Thinner lines
  geom_errorbar(aes(ymin=lb, ymax=ub),
                size=.3,    # Thinner lines
                width=.2,
                position=position_dodge(.9))+
  xlab("Treatment Condition") +
  ylab("Evaluation on Education Policy") + 
  ggtitle("") +
  theme(plot.title = element_text(hjust = 0.5)) +
  scale_fill_manual(values=c("grey", "grey32")) +
  scale_y_continuous(breaks=seq(0, 5, 0.5)) # Ticks from 0-5, every 0.5

ggplot(graph_economy_data, aes(x=group, y=mean)) + 
  theme_classic(base_size = 15) + 
  geom_bar(position=position_dodge(), stat="identity",
           colour="black", # Use black outlines,
           size=.3) +      # Thinner lines
  geom_errorbar(aes(ymin=lb, ymax=ub),
                size=.3,    # Thinner lines
                width=.2,
                position=position_dodge(.9))+
  xlab("Treatment Condition") +
  ylab("Evaluation on Economic Policy") + 
  ggtitle("") +
  theme(plot.title = element_text(hjust = 0.5)) +
  scale_fill_manual(values=c("grey", "grey32")) +
  scale_y_continuous(breaks=seq(0, 5, 0.5)) # Ticks from 0-5, every 0.5

ggplot(graph_healthcare_data, aes(x=group, y=mean)) + 
  theme_classic(base_size = 15) + 
  geom_bar(position=position_dodge(), stat="identity",
           colour="black", # Use black outlines,
           size=.3) +      # Thinner lines
  geom_errorbar(aes(ymin=lb, ymax=ub),
                size=.3,    # Thinner lines
                width=.2,
                position=position_dodge(.9))+
  xlab("Treatment Condition") +
  ylab("Evaluation on Healthcare Policy") + 
  ggtitle("") +
  theme(plot.title = element_text(hjust = 0.5)) +
  scale_fill_manual(values=c("grey", "grey32")) +
  scale_y_continuous(breaks=seq(0, 5, 0.5)) # Ticks from 0-5, every 0.5

Graphing the Average Treatment Evaluation by Party by Candidate Party

####Graphical Approach to ATE - Get Average Value by Treatment Assignment 
####Then graph the average value with Confidence Intervals 

std.error <- function(x) sd(x)/sqrt(length(x))

graph_fp_data2 <- becvar_data %>%
  group_by(group_by_party) %>%
  dplyr::summarise(
    mean = mean(education),
    sd = sd(education),
    n = as.numeric(n()),
    se = std.error(education),
    ub = mean+(1.96*se), 
    lb = mean-(1.96*se))

graph_terr_data2 <- becvar_data %>%
  group_by(group_by_party) %>%
  dplyr::summarise(
    mean = mean(education),
    sd = sd(education),
    n = as.numeric(n()),
    se = std.error(education),
    ub = mean+(1.96*se), 
    lb = mean-(1.96*se))

graph_education_data2 <- becvar_data %>%
  group_by(group_by_party) %>%
  dplyr::summarise(
    mean = mean(education),
    sd = sd(education),
    n = as.numeric(n()),
    se = std.error(education),
    ub = mean+(1.96*se), 
    lb = mean-(1.96*se))

graph_economy_data2 <- becvar_data %>%
  group_by(group_by_party) %>%
  dplyr::summarise(
    mean = mean(economy),
    sd = sd(economy),
    n = as.numeric(n()),
    se = std.error(economy),
    ub = mean+(1.96*se), 
    lb = mean-(1.96*se))

graph_healthcare_data2 <- becvar_data %>%
  group_by(group_by_party) %>%
  dplyr::summarise(
    mean = mean(healthcare),
    sd = sd(healthcare),
    n = as.numeric(n()),
    se = std.error(healthcare),
    ub = mean+(1.96*se), 
    lb = mean-(1.96*se))

ggplot(graph_fp_data2, aes(x=group_by_party, y=mean)) + 
  theme_classic(base_size = 15) + 
  geom_bar(position=position_dodge(), stat="identity",
           colour="black", # Use black outlines,
           size=.3) +      # Thinner lines
  geom_errorbar(aes(ymin=lb, ymax=ub),
                size=.3,    # Thinner lines
                width=.2,
                position=position_dodge(.9))+
  xlab("Treatment Condition") +
  ylab("Evaluation on Foreign Policy") + 
  ggtitle("") +
  theme(plot.title = element_text(hjust = 0.5)) +
  scale_fill_manual(values=c("grey", "grey32")) +
  scale_y_continuous(breaks=seq(0, 5, 0.5)) # Ticks from 0-5, every 0.5

ggplot(graph_terr_data2, aes(x=group_by_party, y=mean)) + 
  theme_classic(base_size = 15) + 
  geom_bar(position=position_dodge(), stat="identity",
           colour="black", # Use black outlines,
           size=.3) +      # Thinner lines
  geom_errorbar(aes(ymin=lb, ymax=ub),
                size=.3,    # Thinner lines
                width=.2,
                position=position_dodge(.9))+
  xlab("Treatment Condition") +
  ylab("Evaluation on Terrorism Policy") + 
  ggtitle("") +
  theme(plot.title = element_text(hjust = 0.5)) +
  scale_fill_manual(values=c("grey", "grey32")) +
  scale_y_continuous(breaks=seq(0, 5, 0.5)) # Ticks from 0-5, every 0.5

ggplot(graph_education_data2, aes(x=group_by_party, y=mean)) + 
  theme_classic(base_size = 15) + 
  geom_bar(position=position_dodge(), stat="identity",
           colour="black", # Use black outlines,
           size=.3) +      # Thinner lines
  geom_errorbar(aes(ymin=lb, ymax=ub),
                size=.3,    # Thinner lines
                width=.2,
                position=position_dodge(.9))+
  xlab("Treatment Condition") +
  ylab("Evaluation on Education Policy") + 
  ggtitle("") +
  theme(plot.title = element_text(hjust = 0.5)) +
  scale_fill_manual(values=c("grey", "grey32")) +
  scale_y_continuous(breaks=seq(0, 5, 0.5)) # Ticks from 0-5, every 0.5

ggplot(graph_economy_data2, aes(x=group_by_party, y=mean)) + 
  theme_classic(base_size = 15) + 
  geom_bar(position=position_dodge(), stat="identity",
           colour="black", # Use black outlines,
           size=.3) +      # Thinner lines
  geom_errorbar(aes(ymin=lb, ymax=ub),
                size=.3,    # Thinner lines
                width=.2,
                position=position_dodge(.9))+
  xlab("Treatment Condition") +
  ylab("Evaluation on Economic Policy") + 
  ggtitle("") +
  theme(plot.title = element_text(hjust = 0.5)) +
  scale_fill_manual(values=c("grey", "grey32")) +
  scale_y_continuous(breaks=seq(0, 5, 0.5)) # Ticks from 0-5, every 0.5

ggplot(graph_healthcare_data2, aes(x=group_by_party, y=mean)) + 
  theme_classic(base_size = 15) + 
  geom_bar(position=position_dodge(), stat="identity",
           colour="black", # Use black outlines,
           size=.3) +      # Thinner lines
  geom_errorbar(aes(ymin=lb, ymax=ub),
                size=.3,    # Thinner lines
                width=.2,
                position=position_dodge(.9))+
  xlab("Treatment Condition") +
  ylab("Evaluation on Healthcare Policy") + 
  ggtitle("") +
  theme(plot.title = element_text(hjust = 0.5)) +
  scale_fill_manual(values=c("grey", "grey32")) +
  scale_y_continuous(breaks=seq(0, 5, 0.5)) # Ticks from 0-5, every 0.5

graph_education_data2
## # A tibble: 2 × 7
##   group_by_party  mean    sd     n     se    ub    lb
##   <chr>          <dbl> <dbl> <dbl>  <dbl> <dbl> <dbl>
## 1 Dem_Candidate   2.22  1.16   135 0.100   2.42  2.03
## 2 Rep_Candidate   2.08  1.06   141 0.0889  2.25  1.90

Graphing the policy ownership issues by evaluation of groups by party of evaluator (non-DV outcome variables)

####Graphical Approach to ATE - Get Average Value by Treatment Assignment 
####Then graph the average value with Confidence Intervals 

std.error <- function(x) sd(x)/sqrt(length(x))

graph_education_data2 <- becvar_data %>%
  group_by(group, party) %>%
  dplyr::summarise(
    mean = mean(education),
    sd = sd(education),
    n = as.numeric(n()),
    se = std.error(education),
    ub = mean+(1.96*se), 
    lb = mean-(1.96*se))
## `summarise()` has grouped output by 'group'. You can override using the
## `.groups` argument.
graph_economy_data2 <- becvar_data %>%
  group_by(group, party) %>%
  dplyr::summarise(
    mean = mean(economy),
    sd = sd(economy),
    n = as.numeric(n()),
    se = std.error(economy),
    ub = mean+(1.96*se), 
    lb = mean-(1.96*se))
## `summarise()` has grouped output by 'group'. You can override using the
## `.groups` argument.
graph_healthcare_data2 <- becvar_data %>%
  group_by(group, party) %>%
  dplyr::summarise(
    mean = mean(healthcare),
    sd = sd(healthcare),
    n = as.numeric(n()),
    se = std.error(healthcare),
    ub = mean+(1.96*se), 
    lb = mean-(1.96*se))
## `summarise()` has grouped output by 'group'. You can override using the
## `.groups` argument.
ggplot(graph_education_data2, aes(x=group, y=mean, fill=party)) + 
  theme_classic(base_size = 15) + 
  geom_bar(position=position_dodge(), stat="identity",
           colour="black", # Use black outlines,
           size=.3) +      # Thinner lines
  geom_errorbar(aes(ymin=lb, ymax=ub),
                size=.3,    # Thinner lines
                width=.2,
                position=position_dodge(.9))+
  xlab("Treatment Condition") +
  ylab("Evaluation on Education Policy") + 
  ggtitle("") +
  theme(plot.title = element_text(hjust = 0.5)) +
  scale_fill_manual(values=c("grey", "grey32")) +
  scale_y_continuous(breaks=seq(0, 5, 0.5)) # Ticks from 0-5, every 0.5

ggplot(graph_economy_data2, aes(x=group, y=mean, fill=party)) + 
  theme_classic(base_size = 15) + 
  geom_bar(position=position_dodge(), stat="identity",
           colour="black", # Use black outlines,
           size=.3) +      # Thinner lines
  geom_errorbar(aes(ymin=lb, ymax=ub),
                size=.3,    # Thinner lines
                width=.2,
                position=position_dodge(.9))+
  xlab("Treatment Condition") +
  ylab("Evaluation on Economic Policy") + 
  ggtitle("") +
  theme(plot.title = element_text(hjust = 0.5)) +
  scale_fill_manual(values=c("grey", "grey32")) +
  scale_y_continuous(breaks=seq(0, 5, 0.5)) # Ticks from 0-5, every 0.5

ggplot(graph_healthcare_data2, aes(x=group, y=mean, fill=party)) + 
  theme_classic(base_size = 15) + 
  geom_bar(position=position_dodge(), stat="identity",
           colour="black", # Use black outlines,
           size=.3) +      # Thinner lines
  geom_errorbar(aes(ymin=lb, ymax=ub),
                size=.3,    # Thinner lines
                width=.2,
                position=position_dodge(.9))+
  xlab("Treatment Condition") +
  ylab("Evaluation on Healthcare Policy") + 
  ggtitle("") +
  theme(plot.title = element_text(hjust = 0.5)) +
  scale_fill_manual(values=c("grey", "grey32")) +
  scale_y_continuous(breaks=seq(0, 5, 0.5)) # Ticks from 0-5, every 0.5

Graphing the Average Treatment Evaluation by Gender

####Graphical Approach to ATE - Get Average Value by Treatment Assignment 
####Then graph the average value with Confidence Intervals 

std.error <- function(x) sd(x)/sqrt(length(x))

graph_fp_data2 <- becvar_data %>%
  group_by(group, Gender) %>%
  dplyr::summarise(
    mean_fp = mean(foreignpolicy),
    sd_fp = sd(foreignpolicy),
    n = as.numeric(n()),
    se_fp = std.error(foreignpolicy),
    ub_fp = mean_fp+(1.96*se_fp), 
    lb_fp = mean_fp-(1.96*se_fp))
## `summarise()` has grouped output by 'group'. You can override using the
## `.groups` argument.
graph_ter_data2 <- becvar_data %>%
  group_by(group, Gender) %>%
  dplyr::summarise(
    mean_ter = mean(terrorism),
    sd_ter = sd(terrorism),
    n = as.numeric(n()),
    se_ter = std.error(terrorism),
    ub_ter = mean_ter+(1.96*se_ter), 
    lb_ter = mean_ter-(1.96*se_ter))
## `summarise()` has grouped output by 'group'. You can override using the
## `.groups` argument.
ggplot(graph_fp_data2, aes(x=group, y=mean_fp, fill=Gender)) + 
  theme_classic(base_size = 15) + 
  geom_bar(position=position_dodge(), stat="identity",
           colour="black", # Use black outlines,
           size=.3) +      # Thinner lines
  geom_errorbar(aes(ymin=lb_fp, ymax=ub_fp),
                size=.3,    # Thinner lines
                width=.2,
                position=position_dodge(.9))+
  xlab("Treatment Condition") +
  ylab("Evaluation on Foreign Policy") + 
  ggtitle("") +
  theme(plot.title = element_text(hjust = 0.5)) +
  scale_fill_manual(values=c("grey", "grey32")) +
  scale_y_continuous(breaks=seq(0, 5, 0.5)) # Ticks from 0-5, every 0.5

ggplot(graph_ter_data2, aes(x=group, y=mean_ter, fill=Gender)) + 
  theme_classic(base_size = 15) + 
  geom_bar(position=position_dodge(), stat="identity",
           colour="black", # Use black outlines,
           size=.3) +      # Thinner lines
  geom_errorbar(aes(ymin=lb_ter, ymax=ub_ter),
                size=.3,    # Thinner lines
                width=.2,
                position=position_dodge(.9))+
  xlab("Treatment Condition") +
  ylab("Evaluation on Terrorism") + 
  ggtitle("") +
  theme(plot.title = element_text(hjust = 0.5)) +
  scale_fill_manual(values=c("grey", "grey32")) +
  scale_y_continuous(breaks=seq(0, 5, 0.5)) # Ticks from 0-5, every 0.5

Starting to look specifically at the effects of individual treatments on policy evaluations

#Calculate the average candidate evaluation score by experimental group per hypothesis

#H1: Military experience <> stronger evaluation on foreign policy and terrorism
#H2: Male candidates <> stronger evaluation on foreign policy and terrorism

#Uses linear regression to evaluate "foreign policy" variable by treatment group
lm_1<-lm(foreignpolicy ~ group, data=becvar_data)
summary(lm_1)
## 
## Call:
## lm(formula = foreignpolicy ~ group, data = becvar_data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1.7647 -0.7647 -0.1143  0.6667  2.9143 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   2.5000     0.1738  14.383   <2e-16 ***
## groupF,C,R   -0.3857     0.2440  -1.581   0.1152    
## groupF,V,D   -0.3286     0.2440  -1.346   0.1793    
## groupF,V,R   -0.1667     0.2424  -0.688   0.4923    
## groupM,C,D    0.2647     0.2458   1.077   0.2825    
## groupM,C,R   -0.4143     0.2440  -1.698   0.0907 .  
## groupM,V,D   -0.4062     0.2496  -1.627   0.1048    
## groupM,V,R   -0.2429     0.2440  -0.995   0.3206    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.013 on 268 degrees of freedom
## Multiple R-squared:  0.04686,    Adjusted R-squared:  0.02196 
## F-statistic: 1.882 on 7 and 268 DF,  p-value: 0.0726
#Uses linear regression to evaluate "terrorism" variable by treatment group
lm_2<-lm(terrorism ~ group, data=becvar_data)
summary(lm_2)
## 
## Call:
## lm(formula = terrorism ~ group, data = becvar_data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -2.0000 -0.8823 -0.2188  0.7812  2.7812 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  2.85294    0.20655  13.812   <2e-16 ***
## groupF,C,R  -0.48151    0.29001  -1.660   0.0980 .  
## groupF,V,D   0.14706    0.29001   0.507   0.6125    
## groupF,V,R  -0.18627    0.28802  -0.647   0.5184    
## groupM,C,D   0.02941    0.29211   0.101   0.9199    
## groupM,C,R  -0.28151    0.29001  -0.971   0.3326    
## groupM,V,D  -0.63419    0.29664  -2.138   0.0334 *  
## groupM,V,R  -0.36723    0.29001  -1.266   0.2065    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.204 on 268 degrees of freedom
## Multiple R-squared:  0.04259,    Adjusted R-squared:  0.01758 
## F-statistic: 1.703 on 7 and 268 DF,  p-value: 0.1083
#H3: Ingroup partisans <> stronger evaluation on foreign policy and terrorism

#Uses linear regression to evaluate "foreign policy" evaluated by in-party treatment group and out-party treatment group
lm_3<-lm(foreignpolicy ~ democrat, data=becvar_data)
summary(lm_3)
## 
## Call:
## lm(formula = foreignpolicy ~ democrat, data = becvar_data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1.3551 -0.3551 -0.2246  0.6449  2.7754 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)  2.22464    0.08722  25.507   <2e-16 ***
## democrat     0.13043    0.12335   1.057    0.291    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.025 on 274 degrees of freedom
## Multiple R-squared:  0.004065,   Adjusted R-squared:  0.0004298 
## F-statistic: 1.118 on 1 and 274 DF,  p-value: 0.2912
#Uses linear regression to evaluate "terrorism" evaluated by party
lm_4<-lm(terrorism ~ democrat, data=becvar_data)
summary(lm_4)
## 
## Call:
## lm(formula = terrorism ~ democrat, data = becvar_data)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1.6812 -0.6812 -0.5870  0.4130  2.4130 
## 
## Coefficients:
##             Estimate Std. Error t value Pr(>|t|)    
## (Intercept)   2.5870     0.1036  24.983   <2e-16 ***
## democrat      0.0942     0.1464   0.643    0.521    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.216 on 274 degrees of freedom
## Multiple R-squared:  0.001508,   Adjusted R-squared:  -0.002136 
## F-statistic: 0.4138 on 1 and 274 DF,  p-value: 0.5206
#Use tidy  broom package

tidy_lm1 <- tidy(lm_1, conf.int = TRUE)
tidy_lm2 <- tidy(lm_2, conf.int = TRUE)
tidy_lm3 <- tidy(lm_3, conf.int = TRUE)
tidy_lm4 <- tidy(lm_4, conf.int = TRUE)

options(scipen = 999)

summary(tidy_lm1)
##      term              estimate          std.error        statistic      
##  Length:8           Min.   :-0.41429   Min.   :0.1738   Min.   :-1.6976  
##  Class :character   1st Qu.:-0.39085   1st Qu.:0.2436   1st Qu.:-1.5922  
##  Mode  :character   Median :-0.28571   Median :0.2440   Median :-1.1707  
##                     Mean   : 0.10255   Mean   :0.2360   Mean   : 0.9407  
##                     3rd Qu.:-0.05882   3rd Qu.:0.2445   3rd Qu.:-0.2465  
##                     Max.   : 2.50000   Max.   :0.2496   Max.   :14.3834  
##     p.value          conf.low         conf.high      
##  Min.   :0.0000   Min.   :-0.8977   Min.   :0.06620  
##  1st Qu.:0.1013   1st Qu.:-0.8733   1st Qu.:0.09238  
##  Median :0.1472   Median :-0.7662   Median :0.19478  
##  Mean   :0.1982   Mean   :-0.3621   Mean   :0.56714  
##  3rd Qu.:0.2920   3rd Qu.:-0.5377   3rd Qu.:0.42006  
##  Max.   :0.4923   Max.   : 2.1578   Max.   :2.84221
summary(tidy_lm2)
##      term              estimate          std.error        statistic      
##  Length:8           Min.   :-0.63419   Min.   :0.2066   Min.   :-2.1379  
##  Class :character   1st Qu.:-0.39580   1st Qu.:0.2895   1st Qu.:-1.3648  
##  Mode  :character   Median :-0.23389   Median :0.2900   Median :-0.8087  
##                     Mean   : 0.13484   Mean   :0.2804   Mean   : 0.9673  
##                     3rd Qu.: 0.05882   3rd Qu.:0.2905   3rd Qu.: 0.2023  
##                     Max.   : 2.85294   Max.   :0.2966   Max.   :13.8123  
##     p.value           conf.low         conf.high       
##  Min.   :0.00000   Min.   :-1.2182   Min.   :-0.05016  
##  1st Qu.:0.08187   1st Qu.:-0.9668   1st Qu.: 0.17520  
##  Median :0.26955   Median :-0.8029   Median : 0.33514  
##  Mean   :0.34016   Mean   :-0.4173   Mean   : 0.68695  
##  3rd Qu.:0.54190   3rd Qu.:-0.5153   3rd Qu.: 0.63291  
##  Max.   :0.91987   Max.   : 2.4463   Max.   : 3.25961
summary(tidy_lm3)
##      term              estimate        std.error         statistic     
##  Length:2           Min.   :0.1304   Min.   :0.08722   Min.   : 1.057  
##  Class :character   1st Qu.:0.6540   1st Qu.:0.09625   1st Qu.: 7.170  
##  Mode  :character   Median :1.1775   Median :0.10528   Median :13.282  
##                     Mean   :1.1775   Mean   :0.10528   Mean   :13.282  
##                     3rd Qu.:1.7011   3rd Qu.:0.11431   3rd Qu.:19.394  
##                     Max.   :2.2246   Max.   :0.12335   Max.   :25.507  
##     p.value           conf.low         conf.high     
##  Min.   :0.00000   Min.   :-0.1124   Min.   :0.3733  
##  1st Qu.:0.07281   1st Qu.: 0.4289   1st Qu.:0.8790  
##  Median :0.14561   Median : 0.9703   Median :1.3848  
##  Mean   :0.14561   Mean   : 0.9703   Mean   :1.3848  
##  3rd Qu.:0.21842   3rd Qu.: 1.5116   3rd Qu.:1.8906  
##  Max.   :0.29123   Max.   : 2.0529   Max.   :2.3963
summary(tidy_lm4)
##      term              estimate        std.error        statistic      
##  Length:2           Min.   :0.0942   Min.   :0.1035   Min.   : 0.6433  
##  Class :character   1st Qu.:0.7174   1st Qu.:0.1143   1st Qu.: 6.7283  
##  Mode  :character   Median :1.3406   Median :0.1250   Median :12.8132  
##                     Mean   :1.3406   Mean   :0.1250   Mean   :12.8132  
##                     3rd Qu.:1.9638   3rd Qu.:0.1357   3rd Qu.:18.8982  
##                     Max.   :2.5870   Max.   :0.1464   Max.   :24.9832  
##     p.value          conf.low         conf.high     
##  Min.   :0.0000   Min.   :-0.1941   Min.   :0.3825  
##  1st Qu.:0.1301   1st Qu.: 0.4502   1st Qu.:0.9846  
##  Median :0.2603   Median : 1.0945   Median :1.5866  
##  Mean   :0.2603   Mean   : 1.0945   Mean   :1.5866  
##  3rd Qu.:0.3904   3rd Qu.: 1.7388   3rd Qu.:2.1887  
##  Max.   :0.5206   Max.   : 2.3831   Max.   :2.7908
aug_lm1 <- augment(lm_1, se_fit = TRUE)
aug_lm2 <- augment(lm_2, se_fit = TRUE)

graph_lm1 <- aug_lm1 %>%
  group_by(group) %>%
  summarise_at(vars(.fitted),
               list(mean_fp = mean))

graph_lm2 <- aug_lm2 %>%
  group_by(group) %>%
  summarise_at(vars(.fitted),
               list(mean_ter = mean))

graph_lm1
## # A tibble: 8 × 2
##   group mean_fp
##   <chr>   <dbl>
## 1 F,C,D    2.50
## 2 F,C,R    2.11
## 3 F,V,D    2.17
## 4 F,V,R    2.33
## 5 M,C,D    2.76
## 6 M,C,R    2.09
## 7 M,V,D    2.09
## 8 M,V,R    2.26
aug_lm1
## # A tibble: 276 × 9
##    foreignpolicy group .fitted .se.fit  .resid   .hat .sigma  .cooksd .std.resid
##            <dbl> <chr>   <dbl>   <dbl>   <dbl>  <dbl>  <dbl>    <dbl>      <dbl>
##  1             1 F,V,R    2.33   0.169 -1.33   0.0278   1.01  6.36e-3    -1.33  
##  2             5 M,V,R    2.26   0.171  2.74   0.0286   1.00  2.77e-2     2.75  
##  3             2 F,C,R    2.11   0.171 -0.114  0.0286   1.02  4.81e-5    -0.114 
##  4             2 M,V,R    2.26   0.171 -0.257  0.0286   1.02  2.44e-4    -0.257 
##  5             3 F,C,D    2.50   0.174  0.500  0.0294   1.01  9.50e-4     0.501 
##  6             2 M,C,R    2.09   0.171 -0.0857 0.0286   1.02  2.71e-5    -0.0858
##  7             1 F,C,R    2.11   0.171 -1.11   0.0286   1.01  4.57e-3    -1.12  
##  8             3 F,V,D    2.17   0.171  0.829  0.0286   1.01  2.53e-3     0.829 
##  9             4 F,C,D    2.50   0.174  1.50   0.0294   1.01  8.55e-3     1.50  
## 10             2 M,C,R    2.09   0.171 -0.0857 0.0286   1.02  2.71e-5    -0.0858
## # ℹ 266 more rows

Now I’m revisiting the outcome variables of the feeling thermometer and the support thermometer.

####Graphical Approach to ATE - Get Average Value by Treatment Assignment 
####Then graph the average value with Confidence Intervals 

std.error <- function(x) sd(x)/sqrt(length(x))

graph_feeling_data <- becvar_data %>%
  group_by(group, party) %>%
  dplyr::summarise(
    mean_feeling = mean(feeling),
    sd_feeling = sd(feeling),
    n = as.numeric(n()),
    se_feeling = std.error(feeling),
    ub_feeling = mean_feeling+(1.96*se_feeling), 
    lb_feeling = mean_feeling-(1.96*se_feeling))
## `summarise()` has grouped output by 'group'. You can override using the
## `.groups` argument.
graph_support_data <- becvar_data %>%
  group_by(group, party) %>%
  dplyr::summarise(
    mean_support = mean(support),
    sd_support = sd(support),
    n = as.numeric(n()),
    se_support = std.error(support),
    ub_support = mean_support+(1.96*se_support), 
    lb_support = mean_support-(1.96*se_support))
## `summarise()` has grouped output by 'group'. You can override using the
## `.groups` argument.
ggplot(graph_feeling_data, aes(x=group, y=mean_feeling, fill=party)) + 
  theme_classic(base_size = 15) + 
  geom_bar(position=position_dodge(), stat="identity",
           colour="black", # Use black outlines,
           size=.3) +      # Thinner lines
  geom_errorbar(aes(ymin=lb_feeling, ymax=ub_feeling),
                size=.3,    # Thinner lines
                width=.2,
                position=position_dodge(.9))+
  xlab("Treatment Condition") +
  ylab("Warmth Toward Candidate") + 
  ggtitle("") +
  theme(plot.title = element_text(hjust = 0.5)) +
  scale_fill_manual(values=c("grey", "grey32")) +
  scale_y_continuous(breaks=seq(0, 100, 10))   # Ticks from 0-5, every 1

ggplot(graph_support_data, aes(x=group, y=mean_support, fill=party)) + 
  theme_classic(base_size = 15) + 
  geom_bar(position=position_dodge(), stat="identity",
           colour="black", # Use black outlines,
           size=.3) +      # Thinner lines
  geom_errorbar(aes(ymin=lb_support, ymax=ub_support),
                size=.3,    # Thinner lines
                width=.2,
                position=position_dodge(.9))+
  xlab("Treatment Condition") +
  ylab("Support for Candidate") + 
  ggtitle("") +
  theme(plot.title = element_text(hjust = 0.5)) +
  scale_fill_manual(values=c("grey", "grey32")) +
  scale_y_continuous(breaks=seq(0, 100, 10))   # Ticks from 0-5, every 1

Breaking this down further using various things…

fp_data_2 <- becvar_data %>%
  group_by(group) %>%
  get_summary_stats(foreignpolicy, type = "mean_sd")

fp_data_2
## # A tibble: 8 × 5
##   group variable          n  mean    sd
##   <chr> <fct>         <dbl> <dbl> <dbl>
## 1 F,C,D foreignpolicy    34  2.5  1.14 
## 2 F,C,R foreignpolicy    35  2.11 0.867
## 3 F,V,D foreignpolicy    35  2.17 1.10 
## 4 F,V,R foreignpolicy    36  2.33 0.894
## 5 M,C,D foreignpolicy    34  2.76 1.10 
## 6 M,C,R foreignpolicy    35  2.09 0.981
## 7 M,V,D foreignpolicy    32  2.09 0.856
## 8 M,V,R foreignpolicy    35  2.26 1.12
ter_data_2 <- becvar_data %>%
  group_by(group) %>%
  get_summary_stats(terrorism, type = "mean_sd")

ter_data_2
## # A tibble: 8 × 5
##   group variable      n  mean    sd
##   <chr> <fct>     <dbl> <dbl> <dbl>
## 1 F,C,D terrorism    34  2.85  1.23
## 2 F,C,R terrorism    35  2.37  1.19
## 3 F,V,D terrorism    35  3     1.21
## 4 F,V,R terrorism    36  2.67  1.26
## 5 M,C,D terrorism    34  2.88  1.27
## 6 M,C,R terrorism    35  2.57  1.12
## 7 M,V,D terrorism    32  2.22  1.10
## 8 M,V,R terrorism    35  2.49  1.22
becvar_data %>%
  group_by(group) %>%
  identify_outliers(foreignpolicy)
## # A tibble: 25 × 35
##    group   age polparty leaner party     democrat republican gender female  male
##    <chr> <dbl>    <dbl>  <dbl> <chr>        <dbl>      <dbl>  <dbl>  <dbl> <dbl>
##  1 F,C,D    18        1     NA Democrat         1          0      2      1     0
##  2 F,C,D     8        1     NA Democrat         1          0      2      1     0
##  3 F,C,D    52        2     NA Republic…        0          1      2      1     0
##  4 F,C,R    18        2     NA Republic…        0          1      1      0     1
##  5 F,C,R    13        2     NA Republic…        0          1      1      0     1
##  6 F,C,R     5        1     NA Democrat         1          0      2      1     0
##  7 F,C,R    13        2     NA Republic…        0          1      2      1     0
##  8 F,C,R    10        1     NA Democrat         1          0      2      1     0
##  9 F,C,R    12        2     NA Republic…        0          1      1      0     1
## 10 F,C,R    26        1     NA Democrat         1          0      2      1     0
## # ℹ 15 more rows
## # ℹ 25 more variables: Gender <chr>, pt_guns <dbl>, pt_climate <dbl>,
## #   pt_militarization <dbl>, pt_guns_order <dbl>, pt_climate_order <dbl>,
## #   pt_militarization_order <dbl>, group_number <dbl>, treatment_dem <dbl>,
## #   treatment_rep <dbl>, treatment_female <dbl>, treatment_male <dbl>,
## #   treatment_veteran <dbl>, treatment_civilian <dbl>, foreignpolicy <dbl>,
## #   terrorism <dbl>, economy <dbl>, healthcare <dbl>, education <dbl>, …
becvar_data %>%
  cor_test(foreignpolicy, terrorism)
## # A tibble: 1 × 8
##   var1          var2        cor statistic        p conf.low conf.high method 
##   <chr>         <chr>     <dbl>     <dbl>    <dbl>    <dbl>     <dbl> <chr>  
## 1 foreignpolicy terrorism  0.47      8.77 1.98e-16    0.370     0.555 Pearson

Creating new variable tables until I figure this out

becvar_data2 <- becvar_data %>%
  mutate(Respondents = case_when(
    female==1 & democrat==1 ~ "FemaleDemocrat",
    female==1 & republican==1 ~ "FemaleRepublican",
    male==1 & democrat==1 ~ "MaleDemocrat",
    male==1 & republican==1 ~ "MaleRepublican"
    ))

#Descriptive variables of Respondents
freq(becvar_data2$Respondents)

## becvar_data2$Respondents 
##                  Frequency Percent
## FemaleDemocrat          77   27.90
## FemaleRepublican        78   28.26
## MaleDemocrat            61   22.10
## MaleRepublican          60   21.74
## Total                  276  100.00
#H3: Ingroup partisans <> stronger evaluation on foreign policy and terrorism

#Uses linear regression to evaluate "foreign policy" evaluated by in-party treatment group and out-party treatment group
lm_5<-lm(foreignpolicy ~ Respondents, data=becvar_data2)
summary(lm_5)
## 
## Call:
## lm(formula = foreignpolicy ~ Respondents, data = becvar_data2)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1.4426 -0.4426 -0.2500  0.7143  2.7949 
## 
## Coefficients:
##                             Estimate Std. Error t value            Pr(>|t|)    
## (Intercept)                  2.28571    0.11701  19.535 <0.0000000000000002 ***
## RespondentsFemaleRepublican -0.08059    0.16494  -0.489               0.626    
## RespondentsMaleDemocrat      0.15691    0.17599   0.892               0.373    
## RespondentsMaleRepublican   -0.03571    0.17680  -0.202               0.840    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.027 on 272 degrees of freedom
## Multiple R-squared:  0.007203,   Adjusted R-squared:  -0.003747 
## F-statistic: 0.6578 on 3 and 272 DF,  p-value: 0.5787
#Uses linear regression to evaluate "terrorism" evaluated by in-party treatment group and out-party treatment group
lm_6<-lm(terrorism ~ Respondents, data=becvar_data2)
summary(lm_6)
## 
## Call:
## lm(formula = terrorism ~ Respondents, data = becvar_data2)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1.7377 -0.7133 -0.4333  0.5667  2.5667 
## 
## Coefficients:
##                             Estimate Std. Error t value            Pr(>|t|)    
## (Intercept)                  2.63636    0.13864  19.016 <0.0000000000000002 ***
## RespondentsFemaleRepublican  0.06876    0.19544   0.352               0.725    
## RespondentsMaleDemocrat      0.10134    0.20853   0.486               0.627    
## RespondentsMaleRepublican   -0.20303    0.20950  -0.969               0.333    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.217 on 272 degrees of freedom
## Multiple R-squared:  0.008539,   Adjusted R-squared:  -0.002396 
## F-statistic: 0.7809 on 3 and 272 DF,  p-value: 0.5055

Creating Variable for In and Out Group Evaluations paired with appropriate Treatments

becvar_data3 <- becvar_data2 %>%
  mutate(PartyGroup = case_when(
    group_number==1 & Respondents=="FemaleDemocrat" ~ "InGroup",
    group_number==1 & Respondents=="FemaleRepublican" ~ "OutGroup",
    group_number==1 & Respondents=="MaleDemocrat" ~ "InGroup",
    group_number==1 & Respondents=="MaleRepublican" ~ "OutGroup",
    group_number==2 & Respondents=="FemaleDemocrat" ~ "OutGroup",
    group_number==2 & Respondents=="FemaleRepublican" ~ "InGroup",
    group_number==2 & Respondents=="MaleDemocrat" ~ "OutGroup",
    group_number==2 & Respondents=="MaleRepublican" ~ "InGroup",
    group_number==3 & Respondents=="FemaleDemocrat" ~ "InGroup",
    group_number==3 & Respondents=="FemaleRepublican" ~ "OutGroup",
    group_number==3 & Respondents=="MaleDemocrat" ~ "InGroup",
    group_number==3 & Respondents=="MaleRepublican" ~ "OutGroup",
    group_number==4 & Respondents=="FemaleDemocrat" ~ "OutGroup",
    group_number==4 & Respondents=="FemaleRepublican" ~ "InGroup",
    group_number==4 & Respondents=="MaleDemocrat" ~ "OutGroup",
    group_number==4 & Respondents=="MaleRepublican" ~ "InGroup",
    group_number==5 & Respondents=="FemaleDemocrat" ~ "InGroup",
    group_number==5 & Respondents=="FemaleRepublican" ~ "OutGroup",
    group_number==5 & Respondents=="MaleDemocrat" ~ "InGroup",
    group_number==5 & Respondents=="MaleRepublican" ~ "OutGroup",
    group_number==6 & Respondents=="FemaleDemocrat" ~ "OutGroup",
    group_number==6 & Respondents=="FemaleRepublican" ~ "InGroup",
    group_number==6 & Respondents=="MaleDemocrat" ~ "OutGroup",
    group_number==6 & Respondents=="MaleRepublican" ~ "InGroup",
    group_number==7 & Respondents=="FemaleDemocrat" ~ "InGroup",
    group_number==7 & Respondents=="FemaleRepublican" ~ "OutGroup",
    group_number==7 & Respondents=="MaleDemocrat" ~ "InGroup",
    group_number==7 & Respondents=="MaleRepublican" ~ "OutGroup",
    group_number==8 & Respondents=="FemaleDemocrat" ~ "OutGroup",
    group_number==8 & Respondents=="FemaleRepublican" ~ "InGroup",
    group_number==8 & Respondents=="MaleDemocrat" ~ "OutGroup",
    group_number==8 & Respondents=="MaleRepublican" ~ "InGroup",
    ))

#H3: Ingroup partisans <> stronger evaluation on foreign policy and terrorism

#Uses linear regression to evaluate "foreign policy" evaluated by in-party treatment group and out-party treatment group
lm_7<-lm(foreignpolicy ~ PartyGroup, data=becvar_data3)
summary(lm_7)
## 
## Call:
## lm(formula = foreignpolicy ~ PartyGroup, data = becvar_data3)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1.3050 -0.3050 -0.2741  0.6950  2.7259 
## 
## Coefficients:
##                    Estimate Std. Error t value            Pr(>|t|)    
## (Intercept)         2.27407    0.08835   25.74 <0.0000000000000002 ***
## PartyGroupOutGroup  0.03089    0.12361    0.25               0.803    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.027 on 274 degrees of freedom
## Multiple R-squared:  0.0002279,  Adjusted R-squared:  -0.003421 
## F-statistic: 0.06245 on 1 and 274 DF,  p-value: 0.8029
#Uses linear regression to evaluate "terrorism" evaluated by in-party treatment group and out-party treatment group
lm_8<-lm(terrorism ~ PartyGroup, data=becvar_data3)
summary(lm_8)
## 
## Call:
## lm(formula = terrorism ~ PartyGroup, data = becvar_data3)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1.6454 -0.6454 -0.6222  0.3778  2.3778 
## 
## Coefficients:
##                    Estimate Std. Error t value            Pr(>|t|)    
## (Intercept)         2.62222    0.10477  25.029 <0.0000000000000002 ***
## PartyGroupOutGroup  0.02317    0.14658   0.158               0.875    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.217 on 274 degrees of freedom
## Multiple R-squared:  9.117e-05,  Adjusted R-squared:  -0.003558 
## F-statistic: 0.02498 on 1 and 274 DF,  p-value: 0.8745
#Graph results on Foreign Policy

graph_group <- becvar_data3 %>%
  group_by(group, PartyGroup) %>%
  dplyr::summarise(
    mean = mean(foreignpolicy),
    sd = sd(foreignpolicy),
    n = as.numeric(n()),
    se = std.error(foreignpolicy),
    ub = mean+(1.96*se), 
    lb = mean-(1.96*se))
## `summarise()` has grouped output by 'group'. You can override using the
## `.groups` argument.
ggplot(graph_group, aes(x=group, y=mean, fill=PartyGroup)) + 
  theme_classic(base_size = 15) + 
  geom_bar(position=position_dodge(), stat="identity",
           colour="black", # Use black outlines,
           size=.3) +      # Thinner lines
  geom_errorbar(aes(ymin=lb, ymax=ub),
                size=.3,    # Thinner lines
                width=.2,
                position=position_dodge(.9))+
  xlab("Treatment Condition") +
  ylab("Evaluation on Foreign Policy") + 
  ggtitle("") +
  theme(plot.title = element_text(hjust = 0.5)) +
  scale_fill_manual(values=c("grey", "grey32")) +
  scale_y_continuous(breaks=seq(0, 5, 0.5)) # Ticks from 0-5, every 0.5

#Graph results on Terrorism

graph_group2 <- becvar_data3 %>%
  group_by(group, PartyGroup) %>%
  dplyr::summarise(
    mean = mean(terrorism),
    sd = sd(terrorism),
    n = as.numeric(n()),
    se = std.error(terrorism),
    ub = mean+(1.96*se), 
    lb = mean-(1.96*se))
## `summarise()` has grouped output by 'group'. You can override using the
## `.groups` argument.
ggplot(graph_group2, aes(x=group, y=mean, fill=PartyGroup)) + 
  theme_classic(base_size = 15) + 
  geom_bar(position=position_dodge(), stat="identity",
           colour="black", # Use black outlines,
           size=.3) +      # Thinner lines
  geom_errorbar(aes(ymin=lb, ymax=ub),
                size=.3,    # Thinner lines
                width=.2,
                position=position_dodge(.9))+
  xlab("Treatment Condition") +
  ylab("Evaluation on Terrorism") + 
  ggtitle("") +
  theme(plot.title = element_text(hjust = 0.5)) +
  scale_fill_manual(values=c("grey", "grey32")) +
  scale_y_continuous(breaks=seq(0, 5, 0.5)) # Ticks from 0-5, every 0.5

#H4: Ingroup partisans <> stronger evaluation on feelings thermometer and support for candidate

#Uses linear regression to evaluate "feelings thermometer" evaluated by in-party treatment group and out-party treatment group
lm_8<-lm(feeling ~ PartyGroup, data=becvar_data3)
summary(lm_8)
## 
## Call:
## lm(formula = feeling ~ PartyGroup, data = becvar_data3)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -59.369  -9.585   1.523  12.631  26.631 
## 
## Coefficients:
##                    Estimate Std. Error t value            Pr(>|t|)    
## (Intercept)          74.585      1.498   49.78 <0.0000000000000002 ***
## PartyGroupOutGroup   -1.216      2.096   -0.58               0.562    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 17.41 on 274 degrees of freedom
## Multiple R-squared:  0.001227,   Adjusted R-squared:  -0.002418 
## F-statistic: 0.3367 on 1 and 274 DF,  p-value: 0.5622
#Uses linear regression to evaluate "terrorism" evaluated by in-party treatment group and out-party treatment group
lm_9<-lm(support ~ PartyGroup, data=becvar_data3)
summary(lm_9)
## 
## Call:
## lm(formula = support ~ PartyGroup, data = becvar_data3)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -73.943  -6.943   1.089  12.057  26.057 
## 
## Coefficients:
##                    Estimate Std. Error t value            Pr(>|t|)    
## (Intercept)          76.911      1.541  49.925 <0.0000000000000002 ***
## PartyGroupOutGroup   -2.968      2.155  -1.377                0.17    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 17.9 on 274 degrees of freedom
## Multiple R-squared:  0.006872,   Adjusted R-squared:  0.003248 
## F-statistic: 1.896 on 1 and 274 DF,  p-value: 0.1696
#Graph results on Feeling

graph_group3 <- becvar_data3 %>%
  group_by(group, PartyGroup) %>%
  dplyr::summarise(
    mean = mean(feeling),
    sd = sd(feeling),
    n = as.numeric(n()),
    se = std.error(feeling),
    ub = mean+(1.96*se), 
    lb = mean-(1.96*se))
## `summarise()` has grouped output by 'group'. You can override using the
## `.groups` argument.
ggplot(graph_group3, aes(x=group, y=mean, fill=PartyGroup)) + 
  theme_classic(base_size = 15) + 
  geom_bar(position=position_dodge(), stat="identity",
           colour="black", # Use black outlines,
           size=.3) +      # Thinner lines
  geom_errorbar(aes(ymin=lb, ymax=ub),
                size=.3,    # Thinner lines
                width=.2,
                position=position_dodge(.9))+
  xlab("Treatment Condition") +
  ylab("Warmth Toward Candidate") + 
  ggtitle("") +
  theme(plot.title = element_text(hjust = 0.5)) +
  scale_fill_manual(values=c("grey", "grey32")) +
  scale_y_continuous(breaks=seq(0, 100, 10))   # Ticks from 0-5, every 1

#Graph results on Support

graph_group4 <- becvar_data3 %>%
  group_by(group, PartyGroup) %>%
  dplyr::summarise(
    mean = mean(support),
    sd = sd(support),
    n = as.numeric(n()),
    se = std.error(support),
    ub = mean+(1.96*se), 
    lb = mean-(1.96*se))
## `summarise()` has grouped output by 'group'. You can override using the
## `.groups` argument.
ggplot(graph_group4, aes(x=group, y=mean, fill=PartyGroup)) + 
  theme_classic(base_size = 15) + 
  geom_bar(position=position_dodge(), stat="identity",
           colour="black", # Use black outlines,
           size=.3) +      # Thinner lines
  geom_errorbar(aes(ymin=lb, ymax=ub),
                size=.3,    # Thinner lines
                width=.2,
                position=position_dodge(.9))+
  xlab("Treatment Condition") +
  ylab("Support For Candidate") + 
  ggtitle("") +
  theme(plot.title = element_text(hjust = 0.5)) +
  scale_fill_manual(values=c("grey", "grey32")) +
  scale_y_continuous(breaks=seq(0, 100, 10))   # Ticks from 0-5, every 1

write_csv(becvar_data3, file = "becvar_data3.csv")
###More formal test of significance using linear regression
#Foreign policy evaluations by in-vs-outgroup and gender status
mlm1<-lm(foreignpolicy ~ PartyGroup*gender, data=becvar_data3)
summary(mlm1)
## 
## Call:
## lm(formula = foreignpolicy ~ PartyGroup * gender, data = becvar_data3)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -1.3636 -0.3636 -0.2907  0.6727  2.8116 
## 
## Coefficients:
##                           Estimate Std. Error t value            Pr(>|t|)    
## (Intercept)                 2.5389     0.2818   9.009 <0.0000000000000002 ***
## PartyGroupOutGroup         -0.1750     0.4107  -0.426               0.670    
## gender                     -0.1752     0.1771  -0.990               0.323    
## PartyGroupOutGroup:gender   0.1387     0.2508   0.553               0.581    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 1.028 on 272 degrees of freedom
## Multiple R-squared:  0.00397,    Adjusted R-squared:  -0.007016 
## F-statistic: 0.3614 on 3 and 272 DF,  p-value: 0.781
stargazer(mlm1, type = "text")
## 
## =====================================================
##                               Dependent variable:    
##                           ---------------------------
##                                  foreignpolicy       
## -----------------------------------------------------
## PartyGroupOutGroup                  -0.175           
##                                     (0.411)          
##                                                      
## gender                              -0.175           
##                                     (0.177)          
##                                                      
## PartyGroupOutGroup:gender            0.139           
##                                     (0.251)          
##                                                      
## Constant                           2.539***          
##                                     (0.282)          
##                                                      
## -----------------------------------------------------
## Observations                          276            
## R2                                   0.004           
## Adjusted R2                         -0.007           
## Residual Std. Error            1.028 (df = 272)      
## F Statistic                   0.361 (df = 3; 272)    
## =====================================================
## Note:                     *p<0.1; **p<0.05; ***p<0.01
#Candidate evaluations by in-vs-outgroup and gender status
mlm2<-lm(support ~ PartyGroup*gender, data=becvar_data3)
summary(mlm2)
## 
## Call:
## lm(formula = support ~ PartyGroup * gender, data = becvar_data3)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -79.873  -7.174   1.988  12.918  29.849 
## 
## Coefficients:
##                           Estimate Std. Error t value            Pr(>|t|)    
## (Intercept)                 83.804      4.813  17.411 <0.0000000000000002 ***
## PartyGroupOutGroup           5.791      7.014   0.826               0.410    
## gender                      -4.561      3.024  -1.508               0.133    
## PartyGroupOutGroup:gender   -5.160      4.283  -1.205               0.229    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 17.56 on 272 degrees of freedom
## Multiple R-squared:  0.05068,    Adjusted R-squared:  0.04021 
## F-statistic:  4.84 on 3 and 272 DF,  p-value: 0.00268
stargazer(mlm2, type = "text")
## 
## =====================================================
##                               Dependent variable:    
##                           ---------------------------
##                                     support          
## -----------------------------------------------------
## PartyGroupOutGroup                   5.791           
##                                     (7.014)          
##                                                      
## gender                              -4.561           
##                                     (3.024)          
##                                                      
## PartyGroupOutGroup:gender           -5.160           
##                                     (4.283)          
##                                                      
## Constant                           83.804***         
##                                     (4.813)          
##                                                      
## -----------------------------------------------------
## Observations                          276            
## R2                                   0.051           
## Adjusted R2                          0.040           
## Residual Std. Error            17.564 (df = 272)     
## F Statistic                 4.840*** (df = 3; 272)   
## =====================================================
## Note:                     *p<0.1; **p<0.05; ***p<0.01
#Candidate evaluations by party and gender status
mlm3<-lm(support ~ PartyGroup*female, data=becvar_data3)
summary(mlm3)
## 
## Call:
## lm(formula = support ~ PartyGroup * female, data = becvar_data3)
## 
## Residuals:
##     Min      1Q  Median      3Q     Max 
## -79.873  -7.174   1.988  12.918  29.849 
## 
## Coefficients:
##                           Estimate Std. Error t value            Pr(>|t|)    
## (Intercept)                79.2424     2.1620  36.652 <0.0000000000000002 ***
## PartyGroupOutGroup          0.6303     3.2068   0.197               0.844    
## female                     -4.5613     3.0242  -1.508               0.133    
## PartyGroupOutGroup:female  -5.1603     4.2828  -1.205               0.229    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Residual standard error: 17.56 on 272 degrees of freedom
## Multiple R-squared:  0.05068,    Adjusted R-squared:  0.04021 
## F-statistic:  4.84 on 3 and 272 DF,  p-value: 0.00268
stargazer(mlm3, type = "text")
## 
## =====================================================
##                               Dependent variable:    
##                           ---------------------------
##                                     support          
## -----------------------------------------------------
## PartyGroupOutGroup                   0.630           
##                                     (3.207)          
##                                                      
## female                              -4.561           
##                                     (3.024)          
##                                                      
## PartyGroupOutGroup:female           -5.160           
##                                     (4.283)          
##                                                      
## Constant                           79.242***         
##                                     (2.162)          
##                                                      
## -----------------------------------------------------
## Observations                          276            
## R2                                   0.051           
## Adjusted R2                          0.040           
## Residual Std. Error            17.564 (df = 272)     
## F Statistic                 4.840*** (df = 3; 272)   
## =====================================================
## Note:                     *p<0.1; **p<0.05; ***p<0.01