library(rio)
library(car)
library(stargazer)
## 
## Please cite as:
##  Hlavac, Marek (2015). stargazer: Well-Formatted Regression and Summary Statistics Tables.
##  R package version 5.2. http://CRAN.R-project.org/package=stargazer
brexitFull <- import("~/Dropbox/academic/papers/referendums/uncertainty/data/united kingdom 2016/BES2015_W10_Panel_v0.3.dta")

set.seed(2017)

This is a data set with 64689 observations and 4247 variables.

brexitFull <- within(brexitFull, {
  
  turnout <- recode(euRefTurnoutRetroW9, "9999=NA")
  vote    <- ifelse(turnout == 0, "Abstain", ifelse(euRefVoteW9 == 1, "Leave", "Remain"))
  
  certaintyRemain <- recode(certaintyUKRemainW8, "9999=NA")
  certaintyLeave  <- recode(certaintyUKLeaveW8,  "9999=NA")

  impactSelf <- recode(leaveImpactSelfW8, "9999=NA")
  impactUK   <- recode(leaveImpactBritainW8, "9999=NA")
  
  proIntegration <- 10 - recode(EUIntegrationSelfW8, "9999=NA")

  party <- recode(generalElectionVoteW9, "0='Would not vote'; 1='Conservative'; 2='Labour'; 3='Liberal Democrat'; 6='UKIP'; 9999=NA; else='Other'", as.factor.result = TRUE)
  
  attention <- recode(polAttentionW8, "9999=NA")
  # trustMPs <- recode(trustMPsW8, "9999=NA")
  
  likeCameron <- recode(likeCameronW8, "9999=NA")
  likeCorbyn <- recode(likeCorbynW8, "9999=NA")
  likeFarage <- recode(likeFarageW8, "9999=NA")
   
  econRetroPersonal <- recode(econPersonalRetroW8, "9999=NA")
  econRetroGeneral <- recode(econGenRetroW8, "9999=NA")
  immigrationEcon <- recode(immigEconW8, "9999=NA")
  immigrationCult <- recode(immigCulturalW8, "9999=NA")
  
  higherEducation <- recode(anyUniW9, "0='No higher education'; 1='Currency enrolled'; 2='Did not complete'; 3='Graduated'; 9999=NA", as.factor.result = TRUE)
  gender <- recode(gender, "1='Male'; 2='Female'", as.factor.result = TRUE)
  income <- recode(profile_gross_household, "16:9999=NA")
  age <- Age
  
  region <- recode(gor, "1='North East'; 2='North West'; 3='Yorkshire and The Humber';
                   4='East Midlands'; 5='West Midlands'; 6='London'; 7='South East';
                   8='South West'; 9='Wales'; 10='Scotland'; 11='Northern Ireland';
                   12=NA", as.factor.result = TRUE)
})

brexit <- subset(brexitFull, select = c(region, age, income, gender, higherEducation, 
                                        attention, party, proIntegration,
                                        impactSelf, impactUK, certaintyLeave, certaintyRemain,
                                        vote, turnout,
                                        likeCameron, likeCorbyn, likeFarage,
                                        immigrationEcon, immigrationCult,
                                        econRetroPersonal, econRetroGeneral))

brexit <- brexit[complete.cases(brexit), ]

stargazer(brexit, type = "html")
Statistic N Mean St. Dev. Min Max
age 3,142 52.948 14.994 15 86
income 3,142 6.962 3.544 1 15
attention 3,142 7.691 1.834 0 10
proIntegration 3,142 3.469 3.208 0 10
impactSelf 3,142 2.942 1.121 1 5
impactUK 3,142 3.673 1.064 1 5
certaintyLeave 3,142 2.718 0.738 1 4
certaintyRemain 3,142 2.961 0.695 1 4
turnout 3,142 0.969 0.173 0 1
likeCameron 3,142 3.500 3.070 0 10
likeCorbyn 3,142 3.986 3.335 0 10
likeFarage 3,142 3.304 3.456 0 10
immigrationEcon 3,142 4.085 1.879 1 7
immigrationCult 3,142 3.818 2.038 1 7
econRetroPersonal 3,142 2.872 0.875 1 5
econRetroGeneral 3,142 2.698 0.885 1 5
brexit <- brexit[sample(1:dim(brexit)[1], 1000, replace = FALSE), ]

stargazer(brexit, type = "html")
Statistic N Mean St. Dev. Min Max
age 1,000 52.279 14.984 15 83
income 1,000 6.970 3.476 1 15
attention 1,000 7.715 1.810 0 10
proIntegration 1,000 3.534 3.248 0 10
impactSelf 1,000 2.950 1.133 1 5
impactUK 1,000 3.691 1.049 1 5
certaintyLeave 1,000 2.714 0.717 1 4
certaintyRemain 1,000 2.963 0.694 1 4
turnout 1,000 0.969 0.173 0 1
likeCameron 1,000 3.491 3.101 0 10
likeCorbyn 1,000 3.987 3.344 0 10
likeFarage 1,000 3.404 3.459 0 10
immigrationEcon 1,000 4.055 1.932 1 7
immigrationCult 1,000 3.800 2.065 1 7
econRetroPersonal 1,000 2.869 0.897 1 5
econRetroGeneral 1,000 2.684 0.886 1 5
save(brexit, file = "brexit_subset.Rdata")

This is a data set with 1000 observations and 21 variables.