Skip to content

Instantly share code, notes, and snippets.

Avatar

Benjamin Daniels bbdaniels

View GitHub Profile
@bbdaniels
bbdaniels / csv.lua
Created Mar 26, 2018 — forked from calebreister/csv.lua
Lua script that converts a CSV file to the LaTeX tabular format
View csv.lua
--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 Jul 25, 2018
Simulate bias of random effects in TS model
View random_effects_bias.do
* 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)))
View Untitled.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View graph-two-bars.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View simulate-iv-ritest.ipynb
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 Nov 8, 2018 — 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.
View Add-sub-functions.md

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

View outwriter.ado
// 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 / minimum-detectable-effect.do
Last active Dec 7, 2018
Power calculations by simulation
View minimum-detectable-effect.do
// 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 Dec 13, 2018
HTML to forward to another page
View forward.html
<!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>
@bbdaniels
bbdaniels / globals.do
Last active Jan 17, 2019
Ben's useful boilerplate for Stata
View globals.do
** 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!