Skip to content

Instantly share code, notes, and snippets.

@Nosferican
Created November 16, 2017 01:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Nosferican/c141036301f9835ef0c84ca071384f49 to your computer and use it in GitHub Desktop.
Save Nosferican/c141036301f9835ef0c84ca071384f49 to your computer and use it in GitHub Desktop.
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])
df[:union] = Vector{Union{Nulls.Null, String}}(get.(Dict([(0, "False"),(1, "True")]), df[:union], Nulls.null))
categorical!(df, [:idcode, :year, :race, :union])
dropnull!(df)
mf = ModelFrame(@formula(ln_wage ~ ttl_exp), df)
y = mf.df[:ln_wage]
X = ModelMatrix(mf).m
mf = ModelFrame(@formula(ln_wage ~ idcode), df);
ModelMatrix(mf).m # Error here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment