Skip to content

Instantly share code, notes, and snippets.

View bbdaniels's full-sized avatar

Benjamin Daniels bbdaniels

View GitHub Profile
@bbdaniels
bbdaniels / csv.lua
Created March 26, 2018 19:03 — forked from calebreister/csv.lua
Lua script that converts a CSV file to the LaTeX tabular format
--To include this file, use
--dofile('csv.lua') or require('csv')
--Function to convert a *SV file to a Lua array
--file: the name of the file to read
--delim: the delimeter (default ',')
function dataToTable(file, delim)
--Set initial values
if delim == nil then --allow delim to be optional
delim = ','
@bbdaniels
bbdaniels / random_effects_bias.do
Created July 25, 2018 13:56
Simulate bias of random effects in TS model
* Simulation: Broken or Fixed Effects?
set matsize 5000
clear all
global graph_opts ///
title(, justification(left) color(black) span pos(11)) ///
graphregion(color(white) lc(white) lw(med) la(center)) /// <- Delete la(center) for version < 15
ylab(,angle(0) nogrid) xtit(,placement(left) justification(left)) ///
yscale(noline) xscale(noline) legend(region(lc(none) fc(none)))
@bbdaniels
bbdaniels / Untitled.ipynb
Last active September 12, 2018 22:57
Test stata
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bbdaniels
bbdaniels / simulate-iv-ritest.ipynb
Created November 5, 2018 19:46
[ritest] with [ivregress]
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@bbdaniels
bbdaniels / Add-sub-functions.md
Created November 8, 2018 21:54 — forked from kbjarkefur/Add-sub-functions.md
How to have to commands in seperate ado-files sharing the same sub-commands in a separate file.

Two commands sharing the same sub-functions

It is common that two ado-files in the same package share a lot of sub-commands (also called utility commands, functions etc.). It is bad practice to write the commands in one file first and copy and paste the sub-commands to the other ado-file. This is ad practice as updating these commands is very likely to lead to errors. This is a part of the DRY coding principle that is one of the few coding paradigms that all computer scientists agree on.

This Gist explains how you can set this up in a Stata environment.

The mySubCommandsXYZ.do file

You should give this file a unique name if you are planning on publishing commands using this method as there will be a name conflict if someone else also have a file called mySubCommandsXYZ.do or whatever you end up calling your file.

This file includes all sub-commands that should be included in the ado-files for the commands. The commands in this file may not have

@bbdaniels
bbdaniels / outwriter.ado
Created November 13, 2018 16:59
Does something
// Write values
forvalues i = 2/`nRows' {
forvalues j = 2/`nCols' {
// Get the placement
local theCol : word `j' of `c(ALPHA)'
local theRow = `i'
// Get the values
local nStars = `anything'_STARS[`=`i'-1',`=`j'-1']
@bbdaniels
bbdaniels / globals.do
Last active January 17, 2019 22:55
Ben's useful boilerplate for Stata
** Load all the adofiles!
local adoFiles : dir `"${directory}/ado/"' files "*.ado"
local adoFiles = subinstr(`" `adoFiles' "', `"""' , "" , .)
foreach adoFile in `adoFiles' {
qui do "${directory}/ado/`adoFile'"
}
** Useful globals for everybody!
@bbdaniels
bbdaniels / minimum-detectable-effect.do
Last active December 7, 2018 20:05
Power calculations by simulation
// Want to know the minimum detectable effect size?
// Explore power for different treatment effect sizes with a given sample size.
clear
set matsize 5000
cap mat drop results
qui forval te = 0(0.1)1 { // Loop over treatment effect sizes (te) of 0 to 1 standard deviations at increments of 0.1 SDs
forval i=1/1000 { // Running this loop 1000 times
clear
@bbdaniels
bbdaniels / forward.html
Created December 13, 2018 23:09
HTML to forward to another page
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.0 Transitional//EN”>
<html>
<head>
<title>Your Page Title</title>
<meta http-equiv="refresh" content="0;url=http://bbdaniels.github.io">
</head>
<body>
<p>Put any cool message you want here.</p>