Skip to content

Instantly share code, notes, and snippets.

Avatar

José Bayoán Santiago Calderón, PhD Nosferican

View GitHub Profile
@Nosferican
Nosferican / Model Matrix Error.jl
Created Nov 16, 2017
Identifying error in StatsModels ModelMatrix
View Model Matrix Error.jl
## Using modified forks to test code (mostly fixed depreciations, but can inspect the changes at the link)
using DataFrames # From https://github.com/JuliaEconometrics/DataFrames.jl
using Feather
using StatsModels # From https://github.com/JuliaEconometrics/StatsModels.jl
df = Feather.read("NLS.feather") # Feather file from Stata's webuse nlswork
df = df[[:idcode, :year, :ln_wage, :age, :race, :union, :ttl_exp]]
df[:idcode] = string.(df[:idcode])
df[:year] = string.(df[:year])
@Nosferican
Nosferican / gist:41b8ed14a823038acc44881be70b582c
Last active Nov 17, 2017
Skeleton for Benchmarking QRupdate
View gist:41b8ed14a823038acc44881be70b582c
## This skeleton provides a framework to develop a benchmark for various routines using QRupdate
## The following example tests the efficiency of obtaining the subset of linearly independent columns from
## various matrices. An application of these procedures is for instrumental least squares estimators (e.g., 2SLS).
using QRupdate
srand(0)
m = Int(1e6)
X = rand(m, 3)
@Nosferican
Nosferican / multiway.R
Created Dec 3, 2017
Multiway clustering in R
View multiway.R
if (!any(grepl(pattern = 'pacman', x = installed.packages()[,1]))) {
install.packages('pacman')
}
pacman::p_load(dplyr, plm, multiwayvcov)
df = data(Grunfeld, package = 'plm')
model = lm(formula = value ~ inv + capital,
data = Grunfeld)
vcov_both = multiwayvcov::cluster.vcov(model, select(Grunfeld, firm, year))
diag(vcov_both)[2:3]
@Nosferican
Nosferican / reghdfe.do
Created Dec 3, 2017
reghdfe multiway clustering
View reghdfe.do
use "http://www.stata-press.com/data/r13/grunfeld", clear
reghdfe mvalue invest kstock, noab cl(company year)
vce
View gist:597bf20e73baf86e66b7ab208715f175
# Author: José Bayoán Santiago Calderón (@Nosferican)
# Set up the environment for this application
using Distributions: Normal, TDist
using Plots: Plot, PyPlotBackend, plot, density, savefig, plot!, pyplot
using StatPlots: StatPlots, @df
using Random: seed!
using Statistics: mean, quantile
using StatsBase: coef, coefnames, confint, countmap, dof_residual, levelsmap,
@Nosferican
Nosferican / mlogit.jl
Last active Oct 3, 2018
Draft of Multinomial Logistic Regression
View mlogit.jl
# This is the draft code for generalizing GLM to vector generalized linear models (VGLM)
# Compared to Stata's mlogit (13.1) and R's multinom {nnet}, need to verify and correct mlogit vcov
# Code tested with Julia v"0.7.0-DEV.4993"
# Special Matrices
using LinearAlgebra: Hermitian, LowerTriangular, UpperTriangular, Diagonal
# Factorizations
using LinearAlgebra: Factorization, qrfact, cholfact!, QRPivoted, norm
# Functions
using LinearAlgebra: mul!, diag, copytri!
View weird_matrix.csv
1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
1.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
1.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 1.0 0.0
1.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
1.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 1.0 0.0
1.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 1.0 0.0
1.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
1.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 1.0 0.0
1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 1.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
View Reverse Dependencies.jl
using Pkg.TOML: parsefile
using Base.Iterators: flatten
pkgs = ((d for d in readdir(dir) if occursin(r"^[(aA-zZ|0-9)]+$", d))
for dir in joinpath.(first(DEPOT_PATH),"registries","General", string.('A':'Z'))) |>
flatten |>
collect
"""
cap(v::AbstractString)
@Nosferican
Nosferican / Example4.1.sas
Created Feb 6, 2019
Patterson and Jones 2006 Example 4.1 (Cmax)
View Example4.1.sas
/*** SAS code for examples in Chapter 4 of ***/
/*** Bioequivalence and Statistics in Clinical Pharmacology, ***/
/*** by Scott Patterson and Byron Jones,***/
/*** Chapman and Hall/CRC Press: Boca Raton, London and New York, 2005.***/
/*** WARNING : PROGRAM OFFERED FOR USE WITHOUT ANY GUARANTEES ***/
/*** NO LIABILITY IS ACCEPTED FOR ANY LOSS RESULTING FROM USE OF ***/
/*** THIS SET OF SAS INTRUCTIONS ***/
View data.csv
id sequence period AUC formulation
1 TT 1 5.634789603169249 T
1 TT 2 6.1779441140506 T
2 TT 1 5.389071729816501 T
2 TT 2 5.081404364984463 T
3 TT 1 5.438079308923196 T
3 TT 2 4.59511985013459 T
4 TT 1 5.43372200355424 T
4 TT 2 5.560681631015528 T
5 TT 1 6.202535517187923 T