Skip to content

Instantly share code, notes, and snippets.

@zilinskyjan
zilinskyjan / CHES_ukr.R
Last active February 2, 2024 19:05
plot CHES party positions
library(tidyverse)
library(haven)
# Get data from https://www.chesdata.eu/ches-europe
## Look for: Special Edition Chapel Hill Expert Surveys (SPEED CHES) - 2023 SPEED CHES - Ukraine
uk <- read_dta("CHES_Ukraine_Feb2024.dta")
# Or run:
# uk <- read_csv("https://raw.githubusercontent.com/zilinskyjan/code-and-data/master/politics/CHES_Ukraine_Feb2024.csv")
@zilinskyjan
zilinskyjan / ces_gender_ideo.do
Created January 29, 2024 23:31
Ideological self-identification chart using the CES2022 data
* Get data from: https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi%3A10.7910/DVN/PR4L8P
use "CCES22_Common_OUTPUT_vv_topost.dta", clear
* net install cibar, from("http://fmwww.bc.edu/RePEc/bocode/c") replace
* ssc install schemepack, replace
gen age = 2022-birthyr
* Keeping the main categories (99.27% of observations)
my_pal <- rcartocolor::carto_pal(n = 7, name = "ag_Sunset")
col2 <- rcartocolor::carto_pal(n=7,name="Burg")
Bold <- rcartocolor::carto_pal(n=12,name="Bold")
Fall2 <- rcartocolor::carto_pal(n=2,name="Fall")
Geyser2 <- rcartocolor::carto_pal(n=2,name="Geyser")
library(showtext)
font_add_google("Outfit", "Outfit")
font_add_google("Cabin", "Cabin")
#font_add_google("Montserrat", "Montserrat")
@zilinskyjan
zilinskyjan / get_active_members_of_congress_twitter_handles.R
Created October 31, 2022 20:20
People who serve in the 117th Congress may have multiple Twitter accounts: get all of them with this script.
library(tidyverse)
allHandles <- read_csv("https://raw.githubusercontent.com/USATODAY/clustering-congress-twitter/main/data/source/cong_handles_master_and_ids08082022.csv")
cong117 <- allHandles %>% filter(c117th==1) %>%
select(
twitter_handle = twitter_lower,
state, district, party, chamber,
Official)
library(tidyverse)
library(haven)
library(labelled)
library(stargazer)
# Download data from: https://dataverse.harvard.edu/file.xhtml?fileId=4363671&version=1.0
d2 <- read_dta("Clean Data, Study 2.dta")
d2$college_grad <- ifelse(d2$edu >= 5,1,0)
* Download Nationscape data
* [either make a cumulative file, or just use Wave 47, June 2020]
* URL: https://www.voterstudygroup.org/publication/nationscape-data-set
gen Men = (gender==2) if !mi(gender)
recode age (18/29=1 "Age: 18-29 years") (30/44=2 "30-44 years") (45/64=3 "45-64 years") (65/110=4 "65+ years"), gen(age_group)
gen registered = (registration==1) if !mi(registration)
gen intendsToVote = (vote_intention==1) if !mi(vote_intention)
@zilinskyjan
zilinskyjan / cbs2016_winner.do
Created September 23, 2020 05:34
2016_winner_expectations
* Get data from Roper center
* Downloadable from: https://ropercenter.cornell.edu/ipoll/study/31114169
use "31114169.DTA"
* Table:
tab hrctrump WIN16 [aw=weight], row nof
* 89% of Clinton voters and 61% of third-party voters expected a Clinton victory
@zilinskyjan
zilinskyjan / obama_voters_CCES_panel_2010_2014.do
Last active November 5, 2019 01:54
How many 2008 Obama voters voted for a Republican congressional candidate in 2010?
* Question: how many 2008 Obama voters voted
* for a Republican congressional candidate in 2010 and then
* voted for Obama in '12?
*
* Asked by Dan Pfeiffer here https://twitter.com/danpfeiffer/status/1191492977429893120
* Step 1: Download the 2010-2014 Cooperative Congressional Election Study Panel Survey
* from https://dataverse.harvard.edu/dataset.xhtml?persistentId=doi%3A10.7910/DVN/TOE8I1
use "CCES_Panel_Full3waves_VV_V4.dta", clear
@article{millennials_democracy,
author = {Jan Zilinsky},
title ={Democratic deconsolidation revisited: Young Europeans are not dissatisfied with democracy},
journal = {Research \& Politics},
volume = {6},
number = {1},
year = {2019},
doi = {10.1177/2053168018814332},
URL = {https://doi.org/10.1177/2053168018814332}
}
@zilinskyjan
zilinskyjan / fwl.do
Created August 15, 2018 04:46
Demonstrating the Frisch–Waugh–Lovell theorem in Stata
clear
set seed 10009
set obs 100
gen x1 = rnormal()
* Induce positive correlation between x1 and x2
gen x2 = rnormal() + .2*x1
* TRUE data-generating process
gen y = 1 + x1 + 5*x2 + rnormal()