This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Load libraries | |
library(tidyverse) | |
library(haven) | |
library(fixest) | |
library(modelsummary) | |
### Download data from https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi:10.7910/DVN/GTEBJA# | |
gwz <- read_rds("data_main.rds") |> | |
mutate(inc_share_diff = inc_share_diff * 100) |> | |
filter(main_sample == 1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Year | Borough | Type | Frequency | whole_bc_redistr | |
---|---|---|---|---|---|
1991 | Adur | District council | Thirds | NA | |
1991 | Allerdale | District council | Whole | NA | |
1991 | Alnwick | District council | Whole | NA | |
1991 | Amber Valley | District council | Thirds | NA | |
1991 | Arun | District council | Whole | NA | |
1991 | Ashfield | District council | Whole | NA | |
1991 | Ashford | District council | Whole | NA | |
1991 | Aylesbury Vale | District council | Whole | NA | |
1991 | Babergh | District council | Whole | NA |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Purpose of this code: estimate a conditional logit model, and | |
### calculate the average effect of changing one non-induced | |
### observation in each stratum to an induced observation. | |
library(survival) | |
library(marginaleffects) | |
data("infert") | |
## Create a subset, and identify a non-induced observation as a | |
## "focal" observation for which we will later change the value |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Purpose of this code: | |
### - To generate pairwise average travel times between Westminster constituencies | |
### - To sample contiguous pairings of Westminster constituencies | |
### - To evaluate the travel times between pairings | |
### - To evaluate the compactness of pairings | |
### Inputs | |
### - Travel time data from https://data.ubdc.ac.uk/datasets/public-transport-travel-time-matrices-for-great-britain-ttm-2023 | |
### - Shapefiles from https://geoportal.statistics.gov.uk/datasets/0d698c9712de4afcac9377367d831c1a_0/explore | |
### - lookups from https://geoportal.statistics.gov.uk/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
dat <- tribble(~party, ~seat_share, ~vote_share, | |
"Lab", 411/632, .338, | |
"Con", 119/632, .237, | |
"LDem", 71/632, .122, | |
"SNP", 9/632, .024, | |
"Ind", 6/632, 0.02, | |
"Ref", 4/632, .143, | |
"Green", 4/632, .068, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(here) | |
library(tidyverse) | |
library(colorspace) | |
library(RColorBrewer) | |
library(hrbrthemes) | |
set.seed(2686) | |
here::i_am("R/rr_cog.R") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### Load libraries | |
library(tidyverse) | |
library(haven) ## for Stata import | |
library(readxl) | |
library(marginaleffects) ## for easy predictions and contrasts | |
library(nnet) ## for nnet::multinom | |
library(furrr) ## to perform computations in parallel | |
### Set fewer workers if you have fewer cores | |
plan(multisession, workers = 12) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### PURPOSE OF THIS CODE: estimate a large model in bam and speed-test | |
### predictions using mgcv::predict.bam and | |
### marginaleffects::predictions with and without discretization and | |
### parallelization | |
### ################################################################## | |
### load libraries | |
### ################################################################## | |
library(mgcv) | |
library(marginaleffects) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(rstan) | |
library(cmdstanr) | |
dat <- read.delim("data_attractiveness_juge_results.csv") | |
### Set subject IDs using the same factor levels | |
subject_levels <- unique(c(dat$ID_left, | |
dat$ID_right)) | |
dat <- dat |> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(tidyverse) | |
library(haven) | |
### Replace your file location here | |
bes <- read_dta("~/Dropbox/bes_data/BES2019_W25_v25.0.dta") | |
### What was turnout like in the panel? | |
bes |> | |
filter(!is.na(localTurnoutRetro)) |> | |
group_by(localTurnoutRetro) |> |
NewerOlder