Skip to content

Instantly share code, notes, and snippets.

View Nosferican's full-sized avatar

José Bayoán Santiago Calderón Nosferican

View GitHub Profile
@Nosferican
Nosferican / Model Matrix Error.jl
Created November 16, 2017 01:47
Identifying error in StatsModels ModelMatrix
## 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 November 17, 2017 22:32
Skeleton for Benchmarking QRupdate
## 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 December 3, 2017 19:24
Multiway clustering in 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 December 3, 2017 19:39
reghdfe multiway clustering
use "http://www.stata-press.com/data/r13/grunfeld", clear
reghdfe mvalue invest kstock, noab cl(company year)
vce
@Nosferican
Nosferican / mlogit.jl
Last active October 3, 2018 20:58
Draft of Multinomial Logistic Regression
# 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!
# 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,
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
@Nosferican
Nosferican / Reverse Dependencies.jl
Created October 25, 2018 18:19
Reverse Dependencies
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 February 6, 2019 02:27
Patterson and Jones 2006 Example 4.1 (Cmax)
/*** 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 ***/
@Nosferican
Nosferican / data.csv
Created August 1, 2019 18:28
Example data
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