Skip to content

Instantly share code, notes, and snippets.

View bbdaniels's full-sized avatar

Benjamin Daniels bbdaniels

View GitHub Profile
@bbdaniels
bbdaniels / unicode-translate.do
Created March 7, 2024 18:36
Translate Unicode
cd "${box}/data/public/"
unicode analyze data.dta
unicode encoding set latin1
unicode translate data.dta
@bbdaniels
bbdaniels / bulk-copy-files.do
Created March 7, 2024 18:06
Bulk copy files
// Move data from Box to git location
foreach file in `: dir "${box}/constructed/" files "*.dta" ' {
local file = subinstr("`file'",".dta","",.)
iecodebook export "${box}/constructed/`file'.dta" ///
using "${git}/data/`file'.xlsx" ///
, save replace sign reset
@bbdaniels
bbdaniels / two-stage-power.do
Created November 1, 2023 20:14
Two stage power calculation
// One run of simulation
cap prog drop powerfinder
prog def powerfinder , rclass
args alloc
// Set up 1000 hypotheses
clear
set obs 1000
gen id = _n
@bbdaniels
bbdaniels / quick-binomial-power.do
Created May 23, 2023 19:42
Quick binomial power graph
power oneproportion 0.62 0.5 , n(50(1)150) graph(recast(line) plotopts(lw(thick) lc(red)) xline(100 131,lc(black)) ylab(0 "0%" 0.5 "50%" 0.8 "80%" 0.69 "69%" 1 "100%") yline(.69 .8,lc(black)) note("") title("") subtitle("") )
@bbdaniels
bbdaniels / bias-controls.co
Created March 23, 2023 19:02
Debiasing regression with controls
// Part 1: De-biasing a parameter estimate using controls
// Develop some data generating process for data X’s and for outcome Y, with some (potentially multi-armed) treatment variable and treatment effect. Like last week, you should strongly consider "simulating" data along the lines of your group project.
// This DGP should include strata groups and continuous covariates, as well as random noise. Make sure that the strata groups affect the outcome Y and are of different sizes, and make the probability that an individual unit receives treatment vary across strata groups. You will want to create the strata groups first, then use a command like expand or merge to add them to an individual-level data set.
cap prog drop runregs
prog def runregs, rclass
syntax anything // sample size goes here (divided by ten)
@bbdaniels
bbdaniels / data.csv
Created March 1, 2023 15:58
Make map images reproducibly using google maps API in R
id latitude longitude type
1 38.922893 -77.06741979 T
2 38.92846854 -77.03038385 T
3 38.90462752 -77.0336025 C
4 38.90776671 -77.00978448 C
5 38.87686969 -77.01313188 T
@bbdaniels
bbdaniels / import-infill.do
Created January 13, 2023 17:23
Rapid import and infill of semi-structured data
global data "${wd}/ppol_528_GuzmanLidia/data/Data_exp"
local data : dir "${data}/xlsx/" files *
clear
tempfile allData
save `allData' , emptyok
cap prog drop infill
prog def infill
syntax anything
qui foreach var of varlist `anything' {
@bbdaniels
bbdaniels / graph-combine.do
Created December 20, 2022 16:05
Graph combine with tempfiles
local graphs ""
local x = 1
foreach var of varlist ///
diarrhea_history_duration tb_history_sputum ///
malaria_history_fevertype pph_history_pph ///
diabetes_history_numblimb {
local title : var lab `var'
local graphs `"`graphs' "\``var''" "'
tempfile `var'
@bbdaniels
bbdaniels / percent-graph-bar.do
Created October 26, 2022 19:55
Percent signs in graph bar in stata
local nb=`.Graph.plotregion1.barlabels.arrnels'
forval i=1/`nb' {
di "`.Graph.plotregion1.barlabels[`i'].text[1]'"
.Graph.plotregion1.barlabels[`i'].text[1]="`.Graph.plotregion1.barlabels[`i'].text[1]'%"
}
.Graph.drawgraph
@bbdaniels
bbdaniels / latex-pdf.tex
Created May 24, 2021 17:28
Add arbitrary PDF in LaTeX
\usepackage{pdfpages} % Allow PDF insert for non-TeX elements
\includepdf[noautoscale=true, pages=1]{pdf/15633-Analytics_coverFINAL_print.pdf}
\includepdf[noautoscale=true, pages=2]{pdf/15633-Analytics_coverFINAL_print.pdf}