Skip to content

Instantly share code, notes, and snippets.

View bquistorff's full-sized avatar

Brian Quistorff bquistorff

View GitHub Profile
@bquistorff
bquistorff / statweave.module
Created August 16, 2015 15:51
LyX module for StatWeave functionality for Stata
#\DeclareLyXModule[statweave->latex,fancyvrb.sty]{Statweave}
#DescriptionBegin
#Allows to use the statistical languages as a literate programming tool via Statweave
#For more info see the LyX example file statweave.lyx.
#Base languages +Unix, DOS, Linux, IML, Shell (but only Opts & code chunk).
#DescriptionEnd
#Category: literate
#Excludes:
Format 35
@bquistorff
bquistorff / Stata-syntax-highlighting-notepad++.xml
Last active June 15, 2022 08:47
Notepad++ syntax highlighting file for Stata code
<NotepadPlus>
<UserLang name="Stata" ext="do ado" udlVersion="2.1">
<Settings>
<Global caseIgnored="yes" allowFoldOfComments="no" foldCompact="no" forcePureLC="2" decimalSeparator="0" />
<Prefix Keywords1="no" Keywords2="no" Keywords3="no" Keywords4="no" Keywords5="no" Keywords6="no" Keywords7="yes" Keywords8="no" />
</Settings>
<KeywordLists>
<Keywords name="Comments">00// 00* 00/// 01 02 03/* 04*/</Keywords>
<Keywords name="Numbers, prefix1"></Keywords>
<Keywords name="Numbers, prefix2"></Keywords>
@bquistorff
bquistorff / cli_smcl_log.do
Created November 20, 2014 04:19
Translates a Stata smcl log into log format
*Callable from the command line for converting a gph to eps's in the right places
global dir_base ".."
translate "${dir_base}/log/smcl/`1'.smcl" "${dir_base}/log/`1'.log", replace linesize(140)
@bquistorff
bquistorff / cli_gph_eps.do
Created November 20, 2014 04:17
Stata script to convert a gph file to eps file.
*Callable from the command line for converting a gph to eps's in the right places
global dir_base ".."
adopath ++ "${dir_base}/code/ado/"
gph2fmt `1'.gph eps
if "`2'"!=""{
gph2fmt `1'.gph `2'
}
@bquistorff
bquistorff / gph2fmt.ado
Created November 20, 2014 04:16
Translates a Stata gph file into other formats (and makes a no title version)
*! converts a *.gph file to another format
* Required globals: dir_base
program gph2fmt
args file fmt
graph use "${dir_base}/fig/gph/`file'", name(toexport)
local temp=regexm("`file'","(.+)\.gph")
local file_name_base=regexs(1)
@bquistorff
bquistorff / cli_build_proj_mlib.do
Created November 20, 2014 04:15
Build's Stata project's mlib of local mata files
* all mata objects used across files (or even just all)
* Should be made into an mlib so you don't have to worry
* about including multiple times.
* This should also help a bit with speed.
*Possibly get some project-specific settings
*qui include ....do
* Load all the mata files in ado/
local mata_files : dir "ado" files "*.mata"
@bquistorff
bquistorff / makefile
Created November 20, 2014 03:55
Makefile for a Stata project
# If you don't list all dependencies for code (because maybe it varies programmatically) then you can force a remake by doing 'make -B <target>. Note that it will remake all dependencies!
#nice-ness. Uncomment a line to enable. Default is +10
#nice_prefix := nice
#nice_prefix := nice -n10
############################# Project-specific Entries ####################
# which entries use parallel and need a windows gateway
# from $grep -r eval_synth . --include="*.do"
@bquistorff
bquistorff / svn_batch_rename.sh
Created November 20, 2014 03:35
Batch renames SVN files
#!/bin/bash
# renames files (and svn mv's them if in svn)
# not sure if this works if there is whitespace in these vars
# use from base of project
findstr=$1
replacestr=$2
# It currently doesn't search in hidden folders
# for no recursion, use:
# for i in *
@bquistorff
bquistorff / rm-non-svn.sh
Created November 20, 2014 03:32
Remove non-versioned files
#! /bin/bash
# Removed non-versioned files recursively (otherwise pipe through grep -v '\\')
svn status | grep ^\? | cut -c 9- | sed -e 's/\\/\//g' | xargs -Ifile rm -rf file
@bquistorff
bquistorff / normalize_gph.py
Created November 20, 2014 02:11
Normalizes a Stata gph file
#! /usr/bin/env python
'''
Normalizes a Stata .gph graph file to remove build-specific information.
Filepaths, dates, times, and random IDs are converted so that the file
will be the same no matter where it is built.
Pass in a file pattern (that is quoted so the shell doesn't expand it).
To do: