Skip to content

Instantly share code, notes, and snippets.

View jjchern's full-sized avatar
🐢

JJ Chen jjchern

🐢
View GitHub Profile
@jjchern
jjchern / 0_reuse_code.js
Created June 29, 2017 21:55
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@jjchern
jjchern / filter_-sp-S3-methods.R
Created March 21, 2016 03:49 — forked from dholstius/filter_-sp-S3-methods.R
filter_() methods for Spatial*DataFrame objects
#' Filter (subset) a Spatial*DataFrame object
#'
#' @param object a \code{Spatial*DataFrame}
#' @param ... see \link{subset}
#' @param .dots
#'
#' @importFrom lazyeval all_dots lazy_eval
#'
#' @return a subset of the original \code{Spatial*DataFrame}
#'
@jjchern
jjchern / accmltng_str.do
Created February 12, 2016 20:01
Accumulating a string in Stata
di "`lala'"
local lala "`lala' haha"
di "`lala'"
local lala "`lala' hehe"
di "`lala'"
@jjchern
jjchern / add_fpg.do
Last active January 8, 2016 00:12
Federal Poverty Guidelines Base and Increments (2010-2015) from the Department of Health & Human Services
**********************************************************************
* 2008 POVERTY GUIDELINES
* http://aspe.hhs.gov/2008-hhs-poverty-guidelines
**********************************************************************
********************
* Add hiu_fpgbase
********************
gen hiu_fpgbase = 10400
@jjchern
jjchern / group_years.do
Created November 11, 2015 15:55
group_years.do
replace year = 2 * floor(year / 2)
@jjchern
jjchern / zipCode_to_county.R
Last active November 8, 2015 06:24
Zip code to county link file
# devtools::install_github("jjchern/zipzcta")
# devtools::install_github("jjchern/zcta")
library(dplyr)
# ZIP codes to ZCTAs
zipzcta::zipzcta
# ZCTAs to Counties
zctacounty = zcta::zcta_county_rel_10 %>%
@jjchern
jjchern / gist:80f10f4ec737c743500c
Created November 8, 2015 02:35 — forked from Nimster/gist:2838511
Quick reference to some common R idioms/capabilities - mainly to serve as a reminder for me
### Most of the summary is taken from the awesome R twotorials at http://www.twotorials.com/ by Anthony Damico
### Some of it are my additions from my experience. This is intended so you can Ctrl+F and find what you want using
### common names of functions and concepts from other languages or statistics.
### Troubleshooting: Search http://tolstoy.newcastle.edu.au/R/ , http://www.r-bloggers.com/, http://www.rseek.org/
### Basics
traceback() # Get the call stack after an error, for debugging
32 %% 2 # == 0 mod operator
5 %/% 3 # == 1 integer division
@jjchern
jjchern / matchmcps.do
Last active August 25, 2015 22:24
Matching individuals in CPS March-to-March Supplement
capture program drop matchmcps
program matchmcps
args year
loc year_plus_1 = `year' + 1
// Step 1: Load data for individuals in time t + 1
u mmm.dta if year == `year_plus_1' & mish >= 5, clear
la drop statefip_lbl
@jjchern
jjchern / .Rprofile
Last active July 12, 2017 18:41
My .Rprofile for RStudio projects and for setting global options
## Mainly borrowed from @jennybc
## Location: In root directory of an R project
RPROJ = list(PROJHOME = normalizePath(getwd()))
## Add a cd function, so that I can just cd("input") and then cd("code")
RPROJ$cd = function (subdir) {
sdir = file.path(PROJHOME, subdir)
setwd(sdir)
@jjchern
jjchern / testHtmlWidgets.Rmd
Created July 4, 2015 00:50
Test HTML Widgets in Reveal JS
---
title: "Test"
output: revealjs::revealjs_presentation
---
## Leaflet
```{r, echo=FALSE, results='asis', warning=FALSE}
library(leaflet)
leaflet() %>%
addTiles() %>%