Skip to content

Instantly share code, notes, and snippets.

Avatar

Benjamin Daniels bbdaniels

View GitHub Profile
@bbdaniels
bbdaniels / regression-margins.do
Last active Feb 25, 2021
Using programs in Stata
View regression-margins.do
// Regression margins visualizer
cap prog drop regmargins
prog def regmargins
// Syntax command
syntax anything
// Expected syntax is like regress
// Second entry should be factor variable (i.) and we will visualize levels
@bbdaniels
bbdaniels / posty.do
Created Feb 4, 2021
Arbitrary Monte Carlo dataset with -post- in Stata
View posty.do
sysuse auto.dta , clear
levelsof foreign, local(levels)
tempfile posty
postfile posty str10(a) b c d using `posty' , replace
foreach level in `levels' {
local l : label (foreign) `level'
post posty ("`l'") (2) (3) (4)
@bbdaniels
bbdaniels / asking-for-help.md
Last active Feb 22, 2021
Asking for help with statistical programming
View asking-for-help.md

Asking for help with errors in statistical programming

No matter how experienced you are in statistical programming, you are certain to encounter errors in your code from time to time. You will recognize some of them and be able to solve them quickly, but you will never stop encountering unexpected new errors that you need help to resolve. Asking for help with statistical programming is hard. You need to give enough information to the person helping you so that they can produce the exact same problem you have

View econ-csl
<?xml version="1.0" encoding="utf-8"?>
<style xmlns="http://purl.org/net/xbiblio/csl" class="in-text" version="1.0" page-range-format="chicago" demote-non-dropping-particle="sort-only">
<!-- This style was edited with the Visual CSL Editor (https://editor.citationstyles.org/visualEditor/) -->
<info>
<title>American Political Science Association</title>
<title-short>APSA</title-short>
<id>http://www.zotero.org/styles/american-political-science-association</id>
<link href="http://www.zotero.org/styles/american-political-science-association" rel="self"/>
<link href="http://www.apsanet.org/media/PDFs/Publications/APSAStyleManual2006.pdf" rel="documentation"/>
<author>
View selection-interactive.do
// 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
@bbdaniels
bbdaniels / gtrans.ado
Created Jan 21, 2021
Google Translate for Stata
View gtrans.ado
**
cap prog drop gtrans
prog def gtrans , rclass
syntax anything
preserve
qui {
local theText = subinstr("`anything'"," ","%20",.) // HTML for whitespace
@bbdaniels
bbdaniels / png-2-gif.sh
Created Apr 29, 2020
ImageMagick png to gif
View png-2-gif.sh
convert -delay 20 -loop 0 *.png output.gif
@bbdaniels
bbdaniels / README.md
Last active Mar 23, 2020 — forked from kbjarkefur/README.md
Include link to git commit SHA used to compile pdf in LaTeX
View README.md

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 / intervals.ado
Created Mar 16, 2020
Intervals calculator program for Stata
View intervals.ado
* Intervals program
cap prog drop intervals
prog def intervals
syntax anything [if] [in] [pweight], [Binary]
marksample touse
preserve
qui keep if `touse'
@bbdaniels
bbdaniels / scatter-loadings.do
Created Mar 6, 2020
Loadings graph with arbitrary components
View scatter-loadings.do
// 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'
}