FixedEffectModels.parse_fixedeffectMethod
parse_fixedeffect(data, formula::FormulaTerm)
parse_fixedeffect(data, ts::NTuple{N, AbstractTerm})

Construct any FixedEffect specified with a FixedEffectTerm.

Returns

  • Vector{FixedEffect}: a collection of all FixedEffects constructed.
  • Vector{Symbol}: names assigned to the fixed effects (can be used as column names).
  • FormulaTerm or NTuple{N, AbstractTerm}: formula or ts without any term related to fixed effects (an intercept may be explicitly omitted if necessary).
FixedEffectModels.partial_outMethod

Partial out variables in a Dataframe

Arguments

  • df: A table
  • formula::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 requires CuArrays. In this case, use the option double_precision = false to use Float32.
  • maxiter::Integer: Maximum number of iterations
  • double_precision::Bool: Should the demeaning operation use Float64 rather than Float32? Default to true.
  • tol::Real: Tolerance
  • align::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.regMethod

Estimate a linear model with high dimensional categorical variables / instrumental variables

Arguments

  • df: a Table
  • FormulaTerm: A formula created using @formula
  • CovarianceEstimator: A method to compute the variance-covariance matrix

Keyword arguments

  • contrasts::Dict = Dict() An optional Dict of contrast codings for each categorical variable in the formula. Any unspecified variables will have DummyCoding.
  • weights::Union{Nothing, Symbol} A symbol to refer to a columns for weights
  • save::Symbol: Should residuals and eventual estimated fixed effects saved in a dataframe? Default to :none Use save = :residuals to only save residuals, save = :fe to only save fixed effects, save = :all for both. Once saved, they can then be accessed using residuals() or fe(). The returned DataFrame is automatically aligned with the original DataFrame.
  • method::Symbol: A symbol for the method. Default is :cpu. Alternatively, :gpu requires CuArrays. In this case, use the option double_precision = false to use Float32.
  • nthreads::Integer Number of threads used in estimated. Default to Threads.nthreads() if method = :cpu, else to 256 if method = :gpu.
  • double_precision::Bool: Should the demeaning operation use Float64 rather than Float32? Default to true.
  • tol::Real Tolerance. Default to 1e-8 if double_precision = true, 1e-6 otherwise.
  • maxiter::Integer = 10000: Maximum number of iterations
  • drop_singletons::Bool = true: Should singletons be dropped?
  • progress_bar::Bool = true: Should the regression show a progressbar
  • dof_add::Integer = 0:
  • subset::Union{Nothing, AbstractVector} = nothing: select specific rows

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)))