Skip to content

Instantly share code, notes, and snippets.

View bbdaniels's full-sized avatar

Benjamin Daniels bbdaniels

View GitHub Profile
@bbdaniels
bbdaniels / Simulation: Big effects from small RCTs
Last active January 13, 2020 18:12
Simulation: Big and small effects from RCTs
// Simulation 1: Big effects from small RCTs
cap mat drop results
qui forv iter = 1/1000 {
clear
set obs 10000
gen x = rnormal() > 0
gen e = rnormal() * 4
@bbdaniels
bbdaniels / regression-table.do
Created January 13, 2020 22:34
Create generic regression table using built-in commands.
// Demo code for creating simple regression table
sysuse auto.dta, clear
// Run regressions
reg price weight
su price if e(sample)
estadd scalar mean = r(mean)
est sto reg1
@bbdaniels
bbdaniels / Edgeworth-box.do
Created January 23, 2020 20:18
Edgeworth box in Stata
clear
set obs 100
gen y = runiform() * 3
gen x = runiform() * 3
tw ///
(scatter x y) ///
(scatter x y , m(none) yaxis(2) xaxis(2)) ///
@bbdaniels
bbdaniels / power-curve.do
Last active February 11, 2020 03:11
Make simple power curves for binary variables
tempname a b c
tw (function 1.4*sqrt((2/x)+(2/x)) , range(300 600) lc(red)) ///
(function 1.4*sqrt((3/x)+(3/(2*x))) , range(300 600) lc(red) lp(dash)) ///
(function sqrt(1/x) , range(300 600) lc(black) ) ///
, yscale(r(0)) ytit(" ") xtit("Number of Providers") ///
title("Within Case") ///
ylab(0 .05 "5p.p." .1 "10p.p." .15 "15p.p." .2 "20p.p.") ///
legend(on c(1) pos(9) ///
order( ///
@bbdaniels
bbdaniels / scatter-loadings.do
Created March 6, 2020 19:47
Loadings graph with arbitrary components
// Get arbitrary loadings
// Data
sysuse auto.dta , clear
local variables length mpg price rep78
// Get labels
foreach var of varlist `variables' {
local `var' : var label `var'
}
@bbdaniels
bbdaniels / intervals.ado
Created March 16, 2020 19:22
Intervals calculator program for Stata
* Intervals program
cap prog drop intervals
prog def intervals
syntax anything [if] [in] [pweight], [Binary]
marksample touse
preserve
qui keep if `touse'
@bbdaniels
bbdaniels / README.md
Last active March 23, 2020 13:39 — forked from kbjarkefur/README.md
Include link to git commit SHA used to compile pdf in LaTeX

Automatically include link to current git commit/SHA in compiled LaTeX pdf

This code lets you include an automatically updating link in a LaTeX compiled document that points to the last commit in the branch currently checked out in the repository where the .tex file used to compile the documents is saved. This allows you to track exactly which version of your .tex file was used to generate a given PDF.

Using Git you can then go back to the exact code used when compiling any saved or printed version of your document you find, no matter how long ago it was compiled. The commit SHA (the unique commit ID) will automatically update each time there is a new commit

@bbdaniels
bbdaniels / png-2-gif.sh
Created April 29, 2020 17:17
ImageMagick png to gif
convert -delay 20 -loop 0 *.png output.gif
@bbdaniels
bbdaniels / gtrans.ado
Created January 21, 2021 18:13
Google Translate for Stata
**
cap prog drop gtrans
prog def gtrans , rclass
syntax anything
preserve
qui {
local theText = subinstr("`anything'"," ","%20",.) // HTML for whitespace
@bbdaniels
bbdaniels / selection-interactive.do
Last active February 1, 2021 14:44
Selection simulations
// Selection bias for normally-distributed effect with choice
// Setup
qui {
clear all
cls
version 13
// Reproducibility with bit.ly/stata-random
set seed 422698 // Timestamp: 2021-01-22 16:41:57 UTC