Skip to content

Instantly share code, notes, and snippets.

View jdingel's full-sized avatar

Jonathan Dingel jdingel

View GitHub Profile
@jdingel
jdingel / FJS_DEX.do
Created May 23, 2020 03:21
Use DEX data to produce FJS Figure 1
import delimited using "https://raw.githubusercontent.com/COVIDExposureIndices/COVIDExposureIndices/master/dex_data/state_dex.csv", clear
keep state date dex num_devices dex_a num_devices_a
gen date_stata = date(date,"YMD")
format %td date_stata
gen baseline_date = mod(date_stata - 21934,7)
bys state baseline_date (date_stata): egen baseline_dex_a = total(dex_a * inrange(date_stata,21974,21982))
by state baseline_date (date_stata): egen baseline_denom = total(inrange(date_stata,21974,21982))
gen dex_a_r = dex_a / (baseline_dex_a / baseline_denom)
collapse (min) dex_a_r_min = dex_a_r (max) dex_a_r_max = dex_a_r (p10) dex_a_r_10 = dex_a_r (p25) dex_a_r_25 = dex_a_r (p50) dex_a_r_50 = dex_a_r (p75) dex_a_r_75 = dex_a_r (p90) dex_a_r_90 = dex_a_r (p5) dex_a_r_05 = dex_a_r (p95) dex_a_r_95 = dex_a_r, by(date_stata)
gen byte ins = (inrange(date_stata, 21934+30,22039-21)==1)
@jdingel
jdingel / dex_georgia_gist.do
Created May 8, 2020 02:51
Compare Georgia's DEX to rest of country
import delimited using "https://raw.githubusercontent.com/COVIDExposureIndices/COVIDExposureIndices/master/dex_data/state_dex.csv", clear
keep state date dex num_devices dex_a num_devices_a
gen date_stata = date(date,"YMD")
format %td date_stata
gen baseline_date = mod(date_stata - 21934,7)
bys state baseline_date (date_stata): egen baseline_dex_a = total(dex_a * inrange(date_stata,0,21954))
by state baseline_date (date_stata): egen baseline_denom = total(inrange(date_stata,0,21954))
gen dex_a_relative = dex_a / (baseline_dex_a / baseline_denom)
gen byte Georgia = (state=="GA")
collapse (mean) dex_a_relative [w=num_devices], by(date_stata Georgia)
@jdingel
jdingel / dex_wfh_msa_gist.do
Created April 15, 2020 01:38
Scatterplot of DEX against WFH for MSAs
clear all
import delimited using "https://raw.githubusercontent.com/jdingel/DingelNeiman-workathome/master/MSA_measures/output/MSA_workfromhome.csv", clear
drop if substr(area_name,-4,4)==", PR" //Drop Puerto Rico
clonevar cbsa = area
recode cbsa (70900=12700) (71650=14460) (78100=44140) (79600 = 49340) (70750 = 12620) (71950 = 14860) (72400 = 15540) (73450 = 25540) (94650=30340) (75700 = 35300) (76450 = 35980) (76750 = 38860) (77200 = 39300) (76600=38340) //Recode NECTAs to work with CBSA 2013 definitions
tempfile tf_msa_wfh
label variable teleworkable_emp "Share of jobs that can be done at home"
save `tf_msa_wfh'
@jdingel
jdingel / BHORS.do
Created April 4, 2020 20:46
Look at survey data from BHORS "COVID-19 and Remote Work: An Early Look at US Data"
//Examine age distribution: "Used to work from home and still do" response is monotonically increasing in age
import delimited using "https://raw.githubusercontent.com/johnjosephhorton/remote_work/master/etl/gcs.csv", clear
tab question1answer
tab question1answer age if strpos(question1answer,"None of the above")==0, col nof
//Checking against https://www.bls.gov/news.release/flex2.t01.htm, where the highest share of "Workers who did work at home" is 35 to 44 years at 32%
@jdingel
jdingel / download_essentialmix_nu.sh
Created October 6, 2019 01:12
Download essentialmix.nu tracklistings
#!/bin/sh
for i in {100..115}
do
wget "https://www.essentialmix.nu/?modname=tracklistings&op=view&id=${i}" -O - |
grep -A 4 'Essential Mix</a> Archives' | tail -3 | sed 's/^.*\<b\>\([A-Za-z\ ].*\)\<\/b\> Broadcasted/\1/' | pandoc -f html -t plain | sed 's/\[\]//' | sed 's/^[[:space:]]*//' | sed 's/\-\-\-\-//g' | grep -v '^$' > temp.txt
filename=$(head -1 temp.txt | sed 's/on [SMTWF][a-z]*day/\-/' |
sed 's/\([0-9]*\)[rsth][dsth] \([JFMASOND][a-z]*\), \([12][90][901][0-9]\)/\3\.\2\.\1/' |
sed 's/January/01/' | sed 's/February/02/' | sed 's/March/03/' | sed 's/April/04/' | sed 's/May/05/' | sed 's/June/06/' | sed 's/July/07/' | sed 's/August/08/' | sed 's/September/09/' | sed 's/October/10/' | sed 's/November/11/' | sed 's/December/12/')
mv temp.txt "${filename}.txt"
@jdingel
jdingel / AEA_bibtex_download.sh
Created January 25, 2019 00:57
Shell script to rename AEA journal article PDFs
#!/bin/bash
#This script searches the Downloads folder for AEA journal articles and renames them in "Author - Title (journal Year)" format.
#On Mac OS X, you can't use \| in a basic regular expression, which is what "find" uses by default.
cd ~/Downloads
articles=$(find . -name "[ajmp][aeipo][clpr].[0-9]*.pdf" | sed 's/^.\//\ /' | sed 's/.pdf//' | tr -d '\n')
echo "$articles"
for article in $articles
do
@jdingel
jdingel / NBERwp_rename.sh
Last active July 10, 2019 20:51
Shell script to automatically rename downloaded NBER WP PDFs
#!/bin/bash
#This script searches the Downloads folder for NBER working papers (PDFs starting with "w2") and renames them in "Author - Title (NBER Year)"" format.
cd ~/Downloads
papers=$(find . -name "w2[0-9]*.pdf" | sed 's/^.\//\ /' | sed 's/.pdf//' | tr -d '\n')
echo "$papers"
for wp in $papers
do
curl https://www.nber.org/papers/$wp.ris > temp.txt
grep 'AU' temp.txt | awk -F- '{print $2}' | awk -F, '{printf $1 ","}' > temp2.txt