Skip to content

Instantly share code, notes, and snippets.

View briatte's full-sized avatar

François Briatte briatte

View GitHub Profile
@briatte
briatte / cleanup.sh
Created June 26, 2012 01:40
SRQM scripts (deprecated by GitHub and Stata magics)
### delete tex files in slides folder
cd ~/Documents/Teaching/SRQM/Course
rm *.aux *.dvi *.toc *.log *.nav *.out *.snm *.synctex.gz *.tex.bak *.vrb *.run.xml *-blx.bib *.idx *.fdb_latexmk
### delete log files in replication folder
cd ~/Documents/Teaching/SRQM/Replication/
@briatte
briatte / print.css
Last active October 8, 2015 13:08
SRQM style for README files
/*
Styling for Markdown preview in TextMate, copty to:
~/Library/Application Support/TextMate/Managed/Bundles/Themes.tmbundle/Support/web-themes/SRQM/style.css
*/
@import url(http://fonts.googleapis.com/css?family=Ubuntu:400,500,400italic);
@import url(http://fonts.googleapis.com/css?family=Ubuntu+Mono);
*, p {
font-family: "Ubuntu", sans-serif;
@briatte
briatte / lookfor.R
Last active September 21, 2017 17:07
lookfor -- an equivalent to the -lookfor- Stata command that supports foreign and memisc data objects (part of the questionr package)
lookfor <- function(data,
keywords = "weight|sample",
labels = TRUE,
ignore.case = TRUE) {
# search scope
n <- names(data)
if(!length(n)) stop("there are no names to search in that object")
# search function
look <- function(x) { grep(paste(keywords, collapse="|"), x, ignore.case = ignore.case) }
# names search
@briatte
briatte / ggplot2-map-theme.R
Last active December 12, 2015 04:59
a ggplot2 theme for maps, by Osmo Saloma
# ggplot2 map themes by Osmo Saloma
theme_map = function(base_size=9, base_family="")
{
require(grid)
theme_osa(base_size=base_size, base_family=base_family) %+replace%
theme(axis.line=element_blank(),
axis.text.x=element_blank(),
axis.text.y=element_blank(),
axis.ticks=element_blank(),
@briatte
briatte / imf.R
Last active January 22, 2016 08:10 — forked from chrishanretty/imf.R
remixing Chris Giles' analysis of IMF WEO, threading on Chris Hanretty's R code
# Chris Giles:
#
# "Robustness of IMF data scrutinised", Oct 12 2012:
# http://www.ft.com/intl/cms/s/0/85a0c6c2-1476-11e2-8cf2-00144feabdc0.html#axzz2LKQkV3SH
#
# "Has the IMF proved multipliers are really large? (wonkish)" Oct 12 2012:
# http://blogs.ft.com/money-supply/2012/10/12/has-the-imf-proved-multipliers-are-really-large-wonkish/
#
# "The IMF and multipliers, again", Jan 7 2013:
# http://blogs.ft.com/money-supply/2013/01/07/the-imf-and-multipliers-again/
@briatte
briatte / svyplot.ado
Last active September 19, 2019 10:17
svyplot -- a wrapper for catplot (Stata)
*! 0.2.3 F. Briatte 20mar2013
cap pr drop svyplot
program svyplot
syntax varlist(max=3) [if] [in] [aweight fweight iweight/] ///
[, Reds Blues Ascending Descending Horizontal Ymax(int 100) ///
Float(int 0) Size(real 3.5) ANGLE(int 0) NOPercent XLAb *]
// parse options
@briatte
briatte / lp_plots.do
Created March 9, 2013 22:14
Stata code for the religious majority variables by La Porta et al. in the QOG dataset
use data/qog2011, clear
// religious populations
d lp_*80
local vars = "lp_catho80 lp_muslim80 lp_protmg80 lp_no_cpm80"
// kernel densities
local plot = ""
@briatte
briatte / ggcorr.R
Created March 29, 2013 17:32
ggcorr -- a ggplot2 implementation of arm::corrplot
#' If you like [this approach][1] to correlation matrixes, you might also like
#' the `arm::corrplot` function. Here's a ggplot2 implementation.
#' [1]: http://stackoverflow.com/questions/12196756/significance-level-added-to-matrix-correlation-heatmap-using-ggplot2
ggcorr <- function(x, method = "pairwise", palette = "RdYlGn") {
require(ggplot2)
require(reshape) # edit when reshape2 reaches maturity
M <- cor(x[1:ncol(x)], use = method)
M <- M * lower.tri(M)
@briatte
briatte / findCreditCards.R
Created April 6, 2013 10:06
find credit card information on your disk files (by Jeroen Ooms, arXiv:1303.4808v2)
findCreditCards <- function() {
pattern <- "([0-9]{4}[- ]){3}[0-9]{4}"
path <- "~/Documents"
filelist <- list.files(path, full.names=TRUE, recursive=TRUE)
for (filename in filelist){
if(file.info(filename)$size > 1e6) next
doc <- readLines(filename)
results <- gregexpr(pattern, doc)
output <- unlist(regmatches(doc, results))
if(length(output) > 0){
@briatte
briatte / piketty_saez.r
Last active December 16, 2015 00:39
Piketty and Saez data: U.S. real income (incl. capital gains), 1917-2011; check original for updated values
structure(list(Year = c(1917L, 1918L, 1919L, 1920L, 1921L, 1922L,
1923L, 1924L, 1925L, 1926L, 1927L, 1928L, 1929L, 1930L, 1931L,
1932L, 1933L, 1934L, 1935L, 1936L, 1937L, 1938L, 1939L, 1940L,
1941L, 1942L, 1943L, 1944L, 1945L, 1946L, 1947L, 1948L, 1949L,
1950L, 1951L, 1952L, 1953L, 1954L, 1955L, 1956L, 1957L, 1958L,
1959L, 1960L, 1961L, 1962L, 1963L, 1964L, 1965L, 1966L, 1967L,
1968L, 1969L, 1970L, 1971L, 1972L, 1973L, 1974L, 1975L, 1976L,
1977L, 1978L, 1979L, 1980L, 1981L, 1982L, 1983L, 1984L, 1985L,
1986L, 1987L, 1988L, 1989L, 1990L, 1991L, 1992L, 1993L, 1994L,
1995L, 1996L, 1997L, 1998L, 1999L, 2000L, 2001L, 2002L, 2003L,