Skip to content

Instantly share code, notes, and snippets.

View larsvilhuber's full-sized avatar

Lars Vilhuber larsvilhuber

View GitHub Profile
@larsvilhuber
larsvilhuber / checks_n.do
Created March 29, 2024 13:22
Checks and controls in Stata data flow
. *Check sample sizes
. qui desc using ${scratch}/simple2010
. assert r(N)==1941473
. qui desc using ${scratch}/simple2018
. assert r(N)==2011482
@larsvilhuber
larsvilhuber / download.R
Created March 5, 2024 17:58
Downloading from Zenodo (2024)
# this has worked as of 2024-03-01
# Specific DOI - resolves to a fixed version
zenodo.id <- "123456"
# We will recover the rest from Zenodo API
zenodo.api = "https://zenodo.org/api/records/"
# where to save
dataloc <- here::here("data","downloaded
@larsvilhuber
larsvilhuber / download.do
Last active October 23, 2023 16:01
Conditional Stata download
// this would be the directory to put data
global root : pwd
global data "$root/datadir"
cap mkdir "$data"
// now to the file in question
global nhtsfile "nhts-ascii.zip"
capture confirm file "$data/$nhtsfile"
if _rc != 0 {
// what to do when file does NOT exist
copy https://nhts.ornl.gov/2009/download/Ascii.zip "$data/$nhtsfile"
@larsvilhuber
larsvilhuber / main.m
Last active June 7, 2023 19:36
Sample main.m file for repeated strategies
# Instructions to author:
# - Remove ALL paths in each of the files called. They are not needed.
# - Change all lines related to the bootstrap to read:
# [x_M, vc_bs] = bs_abf(match, id_all, strg, K, start_bs, session, bootstrapsize);
#
# This replaces the entire section from the old README:
# Once the MATLAB data is generated, then need to run the MATLAB script est_abf_**.m (depending on whether interested in PD, BoSLI, BOSHI and on the shorter or expanded versions) and to get the results after this script is finished run the corresponding est_test_***.m script. In all these scripts the appropriate path needs to be updated as indicated. Additionally, in all est_abf_**.m scripts the desired bootstrapping needs to be adjusted for each separate estimation at the parts of code starting with [x_M, vc_bs] (for example at line 87 of est_abf_PD_twohalves.m). The MATLAB scripts call on functions bs_abf.m, chis_prb_gf.m, lik_i_abf.m, ll_abf.m, opt_abf.m, and waldtest_gf.m which are all included in the strategies fol
@larsvilhuber
larsvilhuber / 01_download_sipp1992.do
Created March 3, 2023 03:18
A bunch of Stata do files to download SIPP files from NBER
copy https://data.nber.org/sipp/1992/sipp92w1.zip $extractdir/92w1.zip
copy https://data.nber.org/sipp/1992/sip92w1.dct $extractdir/92w1.dct
copy https://data.nber.org/sipp/1992/sipp92w2.zip $extractdir/92w2.zip
copy https://data.nber.org/sipp/1992/sip92w2.dct $extractdir/92w2.dct
copy https://data.nber.org/sipp/1992/sipp92w3.zip $extractdir/92w3.zip
copy https://data.nber.org/sipp/1992/sip92w3.dct $extractdir/92w3.dct
copy https://data.nber.org/sipp/1992/sipp92w4.zip $extractdir/92w4.zip
copy https://data.nber.org/sipp/1992/sip92w4.dct $extractdir/92w4.dct
copy https://data.nber.org/sipp/1992/sipp92w5.zip $extractdir/92w5.zip
copy https://data.nber.org/sipp/1992/sip92w5.dct $extractdir/92w5.dct
@larsvilhuber
larsvilhuber / upload_files_to_dropbox.sh
Created January 26, 2023 16:15
Short script to upload to Dropbox from the command line
#!/bin/bash
# Based on https://stackoverflow.com/questions/42120767/upload-file-on-linux-cli-to-dropbox-via-bash-sh
# This is in principle superseded by Dropbox CLI
## OAUTH_DROPBOX is pulled from environment
if [ -z $OAUTH_DROPBOX ]
then
echo "No oauth token"
exit 2
#!/bin/bash
if [ -z $SGE_TASK_ID ]
then
for SGE_TASK_ID in $(seq 1 319)
do
export SGE_TASK_ID
source $0
done
else
@larsvilhuber
larsvilhuber / global-libraries.R
Created April 23, 2019 15:43
Install R packages
####################################
# global libraries used everywhere #
####################################
# Package lock in - optional
MRAN.snapshot <- "2019-01-01"
options(repos = c(CRAN = paste0("https://mran.revolutionanalytics.com/snapshot/",MRAN.snapshot)))
pkgTest <- function(x)
{
if (!require(x,character.only = TRUE))
@larsvilhuber
larsvilhuber / start_rstudio.sh
Created August 16, 2022 19:20
Starting Rstudio without authentication
docker run -e DISABLE_AUTH=true -v $WORKSPACE:/home/rstudio --rm -p 8787:8787 $space/$repo
@larsvilhuber
larsvilhuber / config_stata.do
Last active May 27, 2022 15:38
Config file for Stata
// Derived from https://github.com/gslab-econ/template/blob/master/config/config_stata.do
// with minor corrections
clear all
set more off
program main
* *** Add required packages from SSC to this list ***
local ssc_packages ""
* *** Add required packages from SSC to this list ***