Skip to content

Commit

Permalink
git pull error message asking to commit changes first
Browse files Browse the repository at this point in the history
Merge branch 'blais_replication' of https://github.com/sjkiss/CES_Analysis into blais_replication

# Conflicts:
#	R_Scripts/1_master_file.R
#	R_Scripts/2_11_ces00_recode.R
  • Loading branch information
mpolacko committed Jun 17, 2020
2 parents ba11ccd + b8b0907 commit 7b1aee3
Show file tree
Hide file tree
Showing 53 changed files with 533 additions and 876 deletions.
Binary file removed Plots/IM1_union_both&sector_ndp_coefficients.png
Binary file not shown.
Binary file removed Plots/IM2_union_both&sector_ndp_coefficients.png
Binary file not shown.
Binary file removed Plots/IM3_degree&income_ndp_coefficients.png
Binary file not shown.
Binary file removed Plots/M1_ndp_by_sector.png
Binary file not shown.
Binary file removed Plots/M1_union_both&ndp_coefficients.png
Binary file not shown.
Binary file removed Plots/M2_union_both&ndp_coefficients.png
Binary file not shown.
Binary file removed Plots/M3_union_both&ndp_coefficients.png
Binary file not shown.
Binary file removed Plots/M4_union_both&ndp_coefficients.png
Binary file not shown.
Binary file removed Plots/M5_union_both&ndp_coefficients.png
Binary file not shown.
Binary file removed Plots/M6_union_both&ndp_coefficients.png
Binary file not shown.
Binary file removed Plots/M7_union_both&ndp_coefficients.png
Binary file not shown.
Binary file removed Plots/M8_union_both&ndp_coefficients.png
Binary file not shown.
Binary file added Plots/degree_ndp_coefficients.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed Plots/logit_union_ndp.png
Binary file not shown.
Binary file removed Plots/percent_ndp_degree.png
Binary file not shown.
Binary file modified Plots/percent_ndp_union.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Plots/piketty_party_vote_by_degree.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Plots/sector_conservative_1968_2015.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Plots/sector_liberal_1968_2015.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Plots/sector_ndp_1968_2015.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified Plots/share_degree_ces.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed Plots/union_both&ndp_coefficients.png
Binary file not shown.
Binary file modified Plots/union_ndp_coefficients.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion R_Scripts/2_0_recode_file.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@ nrow(ces7980)==2761
nrow(ces84)==3377
nrow(ces88)==3609
####Check that the datasets do not contain the recoded variable names
tail(names(ces74))
tail(names(ces84))
tail(names(ces0411))
tail(names(ces15phone))

#extra checks for ces74
table(ces74$sector)
table(ces74$union)
## Note: If it appears that the loaded datasets include recoded variable names at this point you may neee do uncomment the next line, and run it once
#rm(list = ls(all.names = TRUE)) #will clear all objects includes hidden objects.
#### and then go back up and re-run the code, not re-running the rm() line above again.


#load the here() library
library(here)
###How to use the here()package
Expand Down
72 changes: 44 additions & 28 deletions R_Scripts/2_12_ces0411_recode.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,65 +2,72 @@
library(tidyverse)
library(car)
library(labelled)
library(cesdata)

#load data
data("ces0411")

#------------------------------------------------------------------------------
# Gender is the same variable for all elections 2004-11

#recode Gender (GENDER)
####recode Gender (GENDER)####
#Gender is the same variable for all elections 2004-11

look_for(ces0411, "sex")
ces0411$male<-Recode(ces0411$GENDER, "1=1; 5=0")
val_labels(ces0411$male)<-c(Female=0, Male=1)
#checks
val_labels(ces0411$male)
table(ces0411$male)

#------------------------------------------------------------------------------
###Recode 2004 1st

##### Union ####
#recode Union Respondent (ces04_CPS_S6A)
ces0411$union04<-Recode(ces0411$ces04_CPS_S6A, "1=1; 5=0; else=NA")
ces0411$union04<-Recode(ces0411$ces04_CPS_S6A,
"1=1; 5=0; else=NA")
val_labels(ces0411$union04)<-c(None=0, Union=1)
#checks
val_labels(ces0411$union04)
table(ces0411$union04)

#recode Union Combined (ces04_CPS_S6A and ces04_CPS_S6B)
ces0411 %>%
table(ces0411$ces04_CPS_S6A, ces0411$ces04_CPS_S6B, useNA = "ifany")
802+259+982
# Note! The household union question was only asked if the respondent was not a member of a union or if they didn't answer!!
ces0411 %>%
mutate(union_both04=case_when(
#If the person is in a union OR if the household is in a union, then they get a 1
ces04_CPS_S6A==1 | ces04_CPS_S6B==1 ~ 1,
#If the person is not in a union AND if the household is not in a union then thety get a 0
ces04_CPS_S6A==5 | ces04_CPS_S6B==5 ~ 0,
ces04_CPS_S6A==1 | ces04_CPS_S6B==1 ~ 1,
#If the person is not in a union AND if the household is not in a union then theyy get a 0
ces04_CPS_S6B==5 ~ 0,
ces04_CPS_S6A==8 & ces04_CPS_S6B==8 ~ NA_real_,
ces04_CPS_S6A==9 & ces04_CPS_S6B==9 ~ NA_real_,
TRUE ~0
))->ces0411

table(ces0411$union_both04, useNA = "ifany")
1061+984
val_labels(ces0411$union_both04)<-c(None=0, Union=1)

#checks
val_labels(ces0411$union_both04)<-c(None=0, Union=1)
table(ces0411$union_both04)
table( as_factor(ces0411$ces04_CPS_S6A), as_factor(ces0411$union04))
table( as_factor(ces0411$ces04_CPS_S6B), as_factor(ces0411$union04))
table( as_factor(ces0411$ces04_CPS_S6A), as_factor(ces0411$union_both04))
table( as_factor(ces0411$ces04_CPS_S6B), as_factor(ces0411$union_both04))

table(as_factor(ces0411$union04), as_factor(ces0411$ces04_CPS_S6B))
table(as_factor(ces0411$union_both04), as_factor(ces0411$ces04_CPS_S6A))
table(as_factor(ces0411$union_both04), as_factor(ces0411$ces04_CPS_S6B))
ces0411 %>%
select(ces04_CPS_S6A, ces04_CPS_S6B, union_both04) %>%
group_by(ces04_CPS_S6A, ces04_CPS_S6B, union_both04) %>%
summarize(n=n())

# Some checks
table( as_factor(ces0411$ces04_CPS_S6A), as_factor(ces0411$ces04_CPS_S6B), useNA = "ifany")
table(as_factor(ces0411$union_both04), as_factor(ces0411$ces04_CPS_S6A), useNA = "ifany")
table(as_factor(ces0411$union_both04), as_factor(ces0411$ces04_CPS_S6B), useNA = "ifany")

#recode Education (ces04_CPS_S3)
####Education (ces04_CPS_S3)####
look_for(ces0411, "education")
ces0411$degree04<-Recode(ces0411$ces04_CPS_S3, "9:11=1; 1:8=0; else=NA")
val_labels(ces0411$degree04)<-c(nodegree=0, degree=1)
#checks
val_labels(ces0411$degree04)
table(ces0411$degree04)

#recode Region (ces04_PROVINCE)
#####Region (ces04_PROVINCE)####
look_for(ces0411, "province")
ces0411$region04<-Recode(ces0411$ces04_PROVINCE, "10:13=1; 35=2; 46:59=3; 4=NA; else=NA")
val_labels(ces0411$region04)<-c(Atlantic=1, Ontario=2, West=3)
Expand Down Expand Up @@ -209,16 +216,17 @@ ces0411 %>%
#If the person is in a union OR if the household is in a union, then they get a 1
ces06_CPS_S6A==1 | ces06_CPS_S6B==1 ~ 1,
#If the person is not in a union AND if the household is in a union, then they get a 0
ces06_CPS_S6A==5 | ces06_CPS_S6B==5 ~ 0,
ces06_CPS_S6B==5 ~ 0,
ces06_CPS_S6A==8 & ces06_CPS_S6B==8 ~ NA_real_,
ces06_CPS_S6A==9 & ces06_CPS_S6B==9 ~ NA_real_,
TRUE ~0
))->ces0411

val_labels(ces0411$union_both06)<-c(None=0, Union=1)
#checks
val_labels(ces0411$union_both06)
table(ces0411$union_both06)

table(as_factor(ces0411$ces06_CPS_S6A), as_factor(ces0411$union_both06), useNA = "ifany")
#recode Education (ces06_CPS_S3)
look_for(ces0411, "education")
ces0411$degree06<-Recode(ces0411$ces06_CPS_S3, "9:11=1; 1:8=0; else=NA")
Expand Down Expand Up @@ -272,11 +280,14 @@ table(ces0411$language06)

#recode Non-charter Language (ces06_CPS_S17)
look_for(ces0411, "language")
table(ces0411$ces06_CPS_S17)
ces0411$non_charter_language06<-Recode(ces0411$ces06_CPS_S17, "1:5=0; 8:64=1; 65:66=0; 95:97=1; else=NA")
val_labels(ces0411$non_charter_language06)<-c(Charter=0, Non_Charter=1)
#checks
val_labels(ces0411$non_charter_language06)
table(ces0411$non_charter_language06)
table(ces0411$ces06_CPS_S17, ces0411$non_charter_language06, useNA = "ifany")

table(ces0411$survey, ces0411$non_charter_language06)

#recode Employment (ces06_CPS_S4)
look_for(ces0411, "employed")
Expand Down Expand Up @@ -324,6 +335,7 @@ table(ces0411$party_id06)

#recode Vote (ces06_PES_B4A and ces06_PES_B4B)
look_for(ces0411, "party did you vote")
ces0411$ces06_PES_B4A
ces0411 %>%
mutate(vote06=case_when(
ces06_PES_B4A==1 | ces06_PES_B4B==1 ~ 1,
Expand All @@ -333,7 +345,7 @@ ces0411 %>%
ces06_PES_B4A==0 | ces06_PES_B4B==0 ~ 0,
ces06_PES_B4A==4 | ces06_PES_B4B==4 ~ 4,
))->ces0411

table(ces0411$ces06_PES_B4A, ces0411$vote06)
val_labels(ces0411$vote06)<-c(Other=0, Liberal=1, Conservative=2, NDP=3, Bloc=4, Green=5)
#checks
val_labels(ces0411$vote06)
Expand Down Expand Up @@ -375,16 +387,17 @@ ces0411 %>%
#If the person is in a union OR if the household is in a union, then they get a 1
ces08_CPS_S6A==1 | ces08_CPS_S6B==1 ~ 1,
#If the person is in a union AND if the household is in a union, then they get a 1
ces08_CPS_S6A==5 | ces08_CPS_S6B==5 ~ 0,
ces08_CPS_S6B==5 ~ 0,
ces08_CPS_S6A==8 & ces08_CPS_S6B==8 ~ NA_real_,
ces08_CPS_S6A==9 & ces08_CPS_S6B==9 ~ NA_real_,
TRUE ~ 0
))->ces0411

val_labels(ces0411$union_both08)<-c(None=0, Union=1)
#checks
val_labels(ces0411$union_both08)
table(ces0411$union_both08)

table(as_factor(ces0411$ces08_CPS_S6A), as_factor(ces0411$union_both08), useNA = "ifany")
#recode Education (ces08_CPS_S3)
look_for(ces0411, "education")
ces0411$degree08<-Recode(ces0411$ces08_CPS_S3, "9:11=1; 1:8=0; else=NA")
Expand Down Expand Up @@ -444,6 +457,7 @@ val_labels(ces0411$non_charter_language08)<-c(Charter=0, Non_Charter=1)
#checks
val_labels(ces0411$non_charter_language08)
table(ces0411$non_charter_language08)
table(ces0411$survey, ces0411$non_charter_language08)

#recode Employment (ces08_CPS_S4)
look_for(ces0411, "employed")
Expand Down Expand Up @@ -536,9 +550,10 @@ ces0411 %>%
mutate(union_both11=case_when(
#If the person is in a union OR if the household is in a union, then they get a 1
PES11_93==1 | PES11_94==1 ~ 1,
PES11_93==5 | PES11_94==5 ~ 0,
PES11_94==5 ~ 0,
PES11_93==8 & PES11_94==8 ~ NA_real_,
PES11_93==9 & PES11_94==9 ~ NA_real_,
TRUE~0
))->ces0411

table(as_factor(ces0411$union_both11), as_factor(ces0411$PES11_93))
Expand Down Expand Up @@ -674,3 +689,4 @@ val_labels(ces0411$income11)<-c(Lowest=1, Lower_Middle=2, MIddle=3, Upper_Middle
#checks
val_labels(ces0411$income11)
table(ces0411$income11)

10 changes: 8 additions & 2 deletions R_Scripts/2_13_ces15_recode.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,21 @@ table(ces15phone$union)
ces15phone %>%
mutate(union_both=case_when(
PES15_93==1 | PES15_94==1 ~ 1,
PES15_93==5 | PES15_94==5 ~ 0,
PES15_93==5 & PES15_94==5 ~ 0,
PES15_93==8 & PES15_94==8 ~ NA_real_,
PES15_93==9 & PES15_94==9 ~ NA_real_,
TRUE ~ 0,
))->ces15phone

val_labels(ces15phone$union_both)<-c(None=0, Union=1)
#checks
val_labels(ces15phone$union_both)
table(ces15phone$union_both, useNA="ifany")
table(ces15phone$PES15_93, ces15phone$union_both, useNA="ifany")
table(ces15phone$PES15_93, ces15phone$PES15_94, useNA="ifany")
table(ces15phone$union_both)
table(ces15phone$PES15_93, ces15phone$union_both, useNA="ifany")
table(ces15phone$PES15_94, ces15phone$union_both, useNA="ifany")

#recode Education (CPS15_79)
look_for(ces15phone, "education")
Expand Down Expand Up @@ -82,7 +88,7 @@ table(ces15phone$language)
#recode Non-charter Language (CPS15_90)
look_for(ces15phone, "language")
ces15phone$non_charter_language<-Recode(ces15phone$CPS15_90, "1:5=0; 8:64=1; 65=0; 95:97=1; else=NA")
val_labels(ces15phone$non_charter_language15)<-c(Charter=0, Non_Charter=1)
val_labels(ces15phone$non_charter_language)<-c(Charter=0, Non_Charter=1)
#checks
val_labels(ces15phone$non_charter_language)
table(ces15phone$non_charter_language)
Expand Down
10 changes: 6 additions & 4 deletions R_Scripts/2_2_ces68_recode.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,21 @@ ces68 %>%
var363==3 | var379==3 ~ 1,
var363==4 | var379==4 ~ 1,
#This should only be missing if BOTH are not members, right?
#Note var379 is the spousal activity variable, by setting it to be less than zero, I am including people who anaswered 1 (not a member) and 0 the mysterious unknown category
var363==1 | var379==1 ~ 0,
#Note var379 is the spousal activity variable
var379==0 ~ 0,
#This should only be missing if BOTH are no reply, right?
var363==5 | var379==5 ~ NA_real_,
var379==0 ~ 0,
var363==5 | var379==5 ~ NA_real_

))->ces68

val_labels(ces68$union_both)<-c(None=0, Union=1)
#checks
val_labels(ces68$union_both)
table(ces68$union_both)
table(ces68$union_both, ces68$var363)
table(ces68$union_both, ces68$var379)
table(ces68$union, ces68$var363,useNA = "ifany")
table(ces68$union_both, ces68$var379,useNA = "ifany")

#recode Education (var334)
ces68$degree<-Recode(ces68$var334, "17:20=1; 25:26=1; 1:16=0; 21:24=0; 27=0; 30=NA")
Expand Down
26 changes: 20 additions & 6 deletions R_Scripts/2_4_ces74_recode.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#File to Recode 1974 CES Data for 1974 election
library(cesdata)

#load data
data("ces74")
nrow(ces74)

#recode Gender (V480)
look_for(ces74, "sex")
ces74$male<-Recode(ces74$V480, "1=1; 2=0; 9=NA")
Expand All @@ -13,21 +14,25 @@ table(ces74$male)

#recode Union Household (V477)
look_for(ces74, "union")

ces74$union<-Recode(ces74$V476, "1=1; 2=0; 8=NA")
ces74$union<-Recode(ces74$V477, "1=1; 2=0; 8=0")
val_labels(ces74$union)<-c(None=0, Union=1)
#checks
val_labels(ces74$union)
table(ces74$union)
table(ces74$V476,ces74$V477)
ces74$V477
ces74$V478

#Union Combined variable (identical copy of union)
ces74$union_both<-ces74$union
#checks
val_labels(ces74$union_both)
table(ces74$union_both)

#recode Education (V414)
look_for(ces74, "school")
look_for(ces74, "degree")
ces74$degree<-Recode(ces74$V417, "25=1; 0:13=0")
ces74$degree<-Recode(ces74$V414, "25=1; 0:13=0")
val_labels(ces74$degree)<-c(nodegree=0, degree=1)
#checks
val_labels(ces74$degree)
Expand Down Expand Up @@ -92,8 +97,16 @@ table(ces74$employment)
#recode Sector (V386)
look_for(ces74, "sector")
look_for(ces74, "business")
ces74 %>%
mutate(sector=case_when(
V395==69.25 ~ 1,
V395==71.77 ~ 1,
V386==13 ~ 1,
V386> 0 & V386 < 13 ~ 0,
V381> 0 & V381 < 7 ~ 0,
V381==50 ~ 0,
))->ces74

ces74$sector<-Recode(ces74$V386, "13=1; 1:12=0; else=NA")
val_labels(ces74$sector)<-c(Private=0, Public=1)
#checks
val_labels(ces74$sector)
Expand Down Expand Up @@ -130,7 +143,6 @@ val_labels(ces74$income)<-c(Lowest=1, Lower_Middle=2, MIddle=3, Upper_Middle=4,
#checks
val_labels(ces74$income)
table(ces74$income)
names(ces74)

#recode Community Size (V9)
look_for(ces74, "community")
Expand All @@ -141,3 +153,5 @@ val_labels(ces74$size)<-c(Rural=1, Under_10K=2, Under_100K=3, Under_500K=4, City
#checks
val_labels(ces74$size)
table(ces74$size)

names(ces74)
7 changes: 6 additions & 1 deletion R_Scripts/2_5_ces7980_recode.R
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ ces7980$V1471
table(ces7980$V1471)
ces7980 %>%
mutate(sector=case_when(
#teachers and nurses are added to public sector
V1484==6925 ~ 1,
V1484==7177 ~ 1,
V1484==7230 ~ 1,
#all government employees go to public sector
V1473==13 ~ 1,
#all non-government employees go to zero
Expand Down Expand Up @@ -161,7 +165,7 @@ val_labels(ces7980$income)<-c(Lowest=1, Lower_Middle=2, Middle=3, Upper_Middle=4
val_labels(ces7980$income)
table(ces7980$income)


#--------------------------------------------------------------------------------------------------------------------
####1980
#recode Gender (V2156)
look_for(ces7980, "sex")
Expand Down Expand Up @@ -232,6 +236,7 @@ val_labels(ces7980$party_id80)<-c(Other=0, Liberal=1, Conservative=2, NDP=3)
val_labels(ces7980$party_id80)
table(ces7980$party_id80)
table(ces7980$party_id, ces7980$party_id80)

#recode Vote (V2062)
look_for(ces7980, "vote")
ces7980$vote80<-Recode(ces7980$V2062, "1=1; 2=2; 3=3; 4:5=0; else=NA")
Expand Down
15 changes: 9 additions & 6 deletions R_Scripts/2_7_ces84_recode.R
Original file line number Diff line number Diff line change
Expand Up @@ -104,17 +104,20 @@ look_for(ces84, "employment")

ces84 %>%
mutate(sector=case_when(
#what does your company do (government)
VAR530==13 ~1,
# VAR530<13~0,
# VAR524 >1 ~ 0,
#assume these are teachers and nurses
VAR526> 2710 & VAR526 < 2800 ~ 1,
VAR526> 3129 & VAR526 < 3136 ~ 1,
VAR524 >1 ~ 0,
VAR530==99 ~NA_real_ ,
# VAR530==99 ~NA_real_ ,
#all else gets as per Blais' footnote (reading between the lines)
TRUE ~ 0
))->ces84
ces84$VAR524
ces84$VAR530
table(ces84$VAR524, ces84$sector, useNA='ifany')
table(ces84$VAR524, ces84$VAR530, useNA="ifany")

table(as_factor(ces84$VAR524), ces84$sector, useNA='ifany')
table(as_factor(ces84$VAR524), as_factor(ces84$VAR530), useNA="ifany")
val_labels(ces84$sector)<-c(Private=0, Public=1)
ces84$sector
#checks
Expand Down

0 comments on commit 7b1aee3

Please sign in to comment.