FixedEffectModels.partial_out
— MethodPartial out variables in a Dataframe
Arguments
df
: A tableformula::FormulaTerm
: A formula created using@formula
add_mean::Bool
: Should the initial mean added to the returned variable?method::Symbol
: A symbol for the method. Default is :cpu. Alternatively, :gpu requiresCuArrays
. In this case, use the optiondouble_precision = false
to useFloat32
.maxiter::Integer
: Maximum number of iterationsdouble_precision::Bool
: Should the demeaning operation use Float64 rather than Float32? Default to true.tol::Real
: Tolerancealign::Bool
: Should the returned DataFrame align with the original DataFrame in case of missing values? Default to true
Returns
::DataFrame
: a dataframe with as many columns as there are dependent variables and as many rows as the original dataframe.::Vector{Int}
: a vector of iterations for each column::Vector{Bool}
: a vector of success for each column
Details
partial_out
returns the residuals of a set of variables after regressing them on a set of regressors. The syntax is similar to reg
- but it accepts multiple dependent variables. It returns a dataframe with as many columns as there are dependent variables and as many rows as the original dataframe. The regression model is estimated on only the rows where none of the dependent variables is missing. With the option add_mean = true
, the mean of the initial variable is added to the residuals.
Examples
using RDatasets, DataFrames, FixedEffectModels, Gadfly
df = dataset("datasets", "iris")
result = partial_out(df, @formula(SepalWidth + SepalLength ~ fe(Species)), add_mean = true)
plot(layer(result[1], x="SepalWidth", y="SepalLength", Stat.binmean(n=10), Geom.point),
layer(result[1], x="SepalWidth", y="SepalLength", Geom.smooth(method=:lm)))
FixedEffectModels.reg
— MethodEstimate a linear model with high dimensional categorical variables / instrumental variables
Arguments
df
: a TableFormulaTerm
: A formula created using@formula
CovarianceEstimator
: A method to compute the variance-covariance matrixsave::Union{Bool, Symbol} = false
: Should residuals and eventual estimated fixed effects saved in a dataframe? Usesave = :residuals
to only save residuals. Usesave = :fe
to only save fixed effects,save = true
for both. Once saved, they can then be accessed usingresiduals()
orfe()
. The returned DataFrame is automatically aligned with the original DataFrame.method::Symbol
: A symbol for the method. Default is :cpu. Alternatively, :gpu requiresCuArrays
. In this case, use the optiondouble_precision = false
to useFloat32
.contrasts::Dict = Dict()
An optional Dict of contrast codings for each categorical variable in theformula
. Any unspecified variables will haveDummyCoding
.maxiter::Integer = 10000
: Maximum number of iterationsdouble_precision::Bool
: Should the demeaning operation use Float64 rather than Float32? Default to true.tol::Real
Tolerance. Default to 1e-8 ifdouble_precision = true
, 1e-6 otherwise.
Details
Models with instruments variables are estimated using 2SLS. reg
tests for weak instruments by computing the Kleibergen-Paap rk Wald F statistic, a generalization of the Cragg-Donald Wald F statistic for non i.i.d. errors. The statistic is similar to the one returned by the Stata command ivreg2
.
Examples
using RDatasets, FixedEffectModels
df = dataset("plm", "Cigar")
reg(df, @formula(Sales ~ NDI + fe(State) + fe(State)&Year))
reg(df, @formula(Sales ~ NDI + fe(State)*Year))
reg(df, @formula(Sales ~ (Price ~ Pimin)))
reg(df, @formula(Sales ~ NDI), Vcov.robust())
reg(df, @formula(Sales ~ NDI), Vcov.cluster(:State))
reg(df, @formula(Sales ~ NDI), Vcov.cluster(:State , :Year))
df.YearC = categorical(df.Year)
reg(df, @formula(Sales ~ YearC), contrasts = Dict(:YearC => DummyCoding(base = 80)))