# ANN: RegressionTables.jl produces publication-quality regression tables

**URL:** https://discourse.julialang.org/t/ann-regressiontables-jl-produces-publication-quality-regression-tables/7516
**Category:** Data
**Tags:** announcement
**Created:** [December 5, 2017, 4:02am UTC](https://discourse.julialang.org/t/ann-regressiontables-jl-produces-publication-quality-regression-tables/7516 "2017-12-05T04:02:37Z")
**Posts on this page:** 20
**Page:** 2

<div class="post-metadata">

### Author: ![Nosferican](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nosferican/32/9275_2.png) [@Nosferican](https://discourse.julialang.org/u/Nosferican)
#### Post date: [December 12, 2017, 5:01pm UTC](https://discourse.julialang.org/t/ann-regressiontables-jl-produces-publication-quality-regression-tables/7516/21 "2017-12-12T17:01:05Z")

</div>

The work in progress is the following:

- A separate Regression / Econometrics environment that builds on the IO (CSV/Feather) + DataFrames + StatsBase + StatsModels + GLM
- It will have a suite of various packages that provide more functionality
  - A utility package for various transformations and helpers: generalized within transformation (absorbs fixed effects and handles singletons), first-difference transformation, between estimator, two stage estimators, subset linear independent predictors, etc.
  - Intermediate package for computing the distance and kernel auto-tuners for correlation structures which will then be used to provide Sandwich estimators (multi-way clustering, SHAC, HAC, HC, etc.)
  - The covariance matrices package for sandwich estimators and bootstrapping
  - Regression Hypothesis Tests and Diagnostics: StatsBase will host Wald test, LR, and score tests. Hypothesis testing for various tests will construct the according hypothesis test (Wald test, robust Hausman, etc.)

DataFrames / StatsBase / StatsModels / GLM have been updated so now is a matter of unifying the various packages and finish the implementation of the missing features.

A few comments: in the future `DataFrameRegressionModel` will probably be depreciated in favor of inheritance from `StatsBase.RegressionModel`. Covariance matrices will be able to work with all `RegressionModel` rather than `GLM.GeneralizedLinearModel ` with minimal effort.

---

<div class="post-metadata">

### Author: ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)
#### Post date: [December 12, 2017, 6:49pm UTC](https://discourse.julialang.org/t/ann-regressiontables-jl-produces-publication-quality-regression-tables/7516/22 "2017-12-12T18:49:43Z")

</div>

Could you give me more information about `RegressionModel`? Is that the default form of output that we hope to be standard for all regression code? As in the same syntax for getting the covariance matrix, coefficients, etc?

---

<div class="post-metadata">

### Author: ![Nosferican](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nosferican/32/9275_2.png) [@Nosferican](https://discourse.julialang.org/u/Nosferican)
#### Post date: [December 13, 2017, 4:30am UTC](https://discourse.julialang.org/t/ann-regressiontables-jl-produces-publication-quality-regression-tables/7516/23 "2017-12-13T04:30:46Z")

</div>

See [Abstraction for Statistical Models](https://juliastats.github.io/StatsBase.jl/latest/statmodels.html) for details about the inheritance and supported methods. StatsBase provides a hierarchy to inherit such that regression models in any package can be defined as

```julia
mutable struct MyRegressionModel <: StatsBase.RegressionModel
    ...
end

```

Therefore, for any `<:RegressionModel` struct if one can extract the variance covariance estimate using `vcov(model<:RegressionModel)`. Users will not interact with the covariance estimator directly for most applications. For example,

```julia
model = RegressionModel(StatsModel::Formula,
                        data::DataFrames.AbstractDataFrame,
                        options = @options(vce = HC3))

```

after fitting the model with

```julia
StatsBase.fit!(model)

```

or making a call that triggers `fit!` (e.g., `RegressionModel` or `coeftable`), one can extract the variance covariance with `vcov(model)`. For multiway clustering the clusters will be able to be specified in the Formula à la

```julia
formula = @formula(response ~ exogenous +
                  (endogenous ~ instruments) +
                  (absorb = fixedeffect1 + fixedeffect2) +
                  (cluster = PID + TID))
model = RegressionModel(formula, data,
                        options = @options(vce = HC1))

```

For HAC estimators, there will be a suite that will compute distance metrics based on temporal distance (periods, `Date`, `DateTime`) and spatial (based on coordinates, datum, distance metric, etc.). Given the distance matrices and selected options the kernels will be auto-tuned or use a provided kernel and the multidimensional weights will be mapped to a single correlation structure to be passed to the CovarianceMatrices package.

That’s the main idea, but certain aspects might be modified from now until release. What’s your opinion on the approach?

---

<div class="post-metadata">

### Author: ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)
#### Post date: [December 13, 2017, 4:48am UTC](https://discourse.julialang.org/t/ann-regressiontables-jl-produces-publication-quality-regression-tables/7516/24 "2017-12-13T04:48:46Z")

</div>

That’s great. Thanks for all this work! So much better than R, as long as we all work to maintain that standard for new estimation packages.

---

<div class="post-metadata">

### Author: ![Nosferican](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nosferican/32/9275_2.png) [@Nosferican](https://discourse.julialang.org/u/Nosferican)
#### Post date: [December 13, 2017, 5:05am UTC](https://discourse.julialang.org/t/ann-regressiontables-jl-produces-publication-quality-regression-tables/7516/25 "2017-12-13T05:05:16Z")

</div>

As for estimators, most if not all are transformations to the linear predictor and the response. For first-difference, the implementation matches that of Stata (dropping gaps, and smart frequency identification), but allows to handle categorical variables by not differentiating these. The between estimator will be available for both PID and TID (Stata can be “hacked” for TID by specifying `xtset TID`). The fixed effects work à la reghdfe which is better than the standard `xtreg`, `areg` or `xtivregress`. The random effects currently supports the GLS harmonic mean estimator (same formula for 2SLS which matches Stata’s `xtreg` default, but is slightly different for `xtivregress`). The variance covariance estimators use the same finite sample adjustment as `reghdfe` for most cases. For all models, linear dependent predictors are dropped. GLM will depend on `GLM.jl` so all benefits to making GLM robust will be spread (e.g., finally getting the marginal effects worked out, etc.)

---

<div class="post-metadata">

### Author: ![jmboehm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jmboehm/32/2263_2.png) [@jmboehm](https://discourse.julialang.org/u/jmboehm)
#### Post date: [December 13, 2017, 5:09am UTC](https://discourse.julialang.org/t/ann-regressiontables-jl-produces-publication-quality-regression-tables/7516/26 "2017-12-13T05:09:37Z")

</div>

@IljaK91 That package looks great. At the same time, I feel that the updated vcov matrix should go into the `DataFrameRegressionModel` (or `StatsBase.RegressionModel` in the future).

---

<div class="post-metadata">

### Author: ![jmboehm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jmboehm/32/2263_2.png) [@jmboehm](https://discourse.julialang.org/u/jmboehm)
#### Post date: [December 13, 2017, 5:27am UTC](https://discourse.julialang.org/t/ann-regressiontables-jl-produces-publication-quality-regression-tables/7516/27 "2017-12-13T05:27:03Z")

</div>

@Nosferican It would be great if your package could use `FixedEffectModels.jl` for high dimensional fixed effects in linear models. IMHO this is where Julia has an edge over other econometrics packages (as well as that it’s much easier to write nonlinear estimation code using JuMP, but it might be hard to pack that into your package – [this here](https://github.com/gragusa/MomentBasedEstimators.jl) is an example).

---

<div class="post-metadata">

### Author: ![Nosferican](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nosferican/32/9275_2.png) [@Nosferican](https://discourse.julialang.org/u/Nosferican)
#### Post date: [December 13, 2017, 5:42am UTC](https://discourse.julialang.org/t/ann-regressiontables-jl-produces-publication-quality-regression-tables/7516/28 "2017-12-13T05:42:06Z")

</div>

For the variance covariance a common practice would be

```julia
struct mutable MyModel <: RegressionModel
    ...
    vcov::Hermitian{Float64}
    ...
end
function fit!(model::MyModel)
    ...
    setfield!(model, :vcov, CovarianceMatrices.vcov(MyModel))
    ....
end
vcov(model::MyModel) = getfield(model, :vcov)

```

As for absorption, the generalized within transformation uses the Method of Alternating Projections similar to R’s fle, reghdfe, etc. `lsmr` is currently broken in Julia 0.7-Dev, but other methods could be added eventually. The implementation is [here](https://github.com/JuliaEconometrics/EconUtils.jl/blob/master/src/within.jl) and is quite fast.

Something I am pushing hard for is to have utilities in different packages such that they can be used by other packages very easily (dependent only in sharing basic inheritance). Eventually FixedEffectsModels would be able to just call that utility rather than having to maintain it in-house. Any further development will propagate across all implementations and less code duplication.

---

<div class="post-metadata">

### Author: ![IljaK91](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iljak91/32/44301_2.png) [@IljaK91](https://discourse.julialang.org/u/IljaK91)
#### Post date: [December 13, 2017, 12:13pm UTC](https://discourse.julialang.org/t/ann-regressiontables-jl-produces-publication-quality-regression-tables/7516/29 "2017-12-13T12:13:40Z")

</div>

Just to clarify, is it possible to change the vcov matrix in `DataFrameRegressionModel` to the one produced by `CovarianceMatrices.jl` right now?

---

<div class="post-metadata">

### Author: ![Nosferican](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nosferican/32/9275_2.png) [@Nosferican](https://discourse.julialang.org/u/Nosferican)
#### Post date: [December 14, 2017, 4:37am UTC](https://discourse.julialang.org/t/ann-regressiontables-jl-produces-publication-quality-regression-tables/7516/30 "2017-12-14T04:37:46Z")

</div>

Would just have to update the package and minor declarations. No big issue. However, it would only work for `DataFrameRegressionModel ` which is an undesirable feature. For a quick solution, why not wrap the model fitting and overwrite the `vcov` in a wraper?

---

<div class="post-metadata">

### Author: ![IljaK91](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iljak91/32/44301_2.png) [@IljaK91](https://discourse.julialang.org/u/IljaK91)
#### Post date: [December 15, 2017, 10:43am UTC](https://discourse.julialang.org/t/ann-regressiontables-jl-produces-publication-quality-regression-tables/7516/31 "2017-12-15T10:43:14Z")

</div>

If I knew how to do that, I’d be a happy man 😁

---

<div class="post-metadata">

### Author: ![IljaK91](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iljak91/32/44301_2.png) [@IljaK91](https://discourse.julialang.org/u/IljaK91)
#### Post date: [January 22, 2018, 11:29am UTC](https://discourse.julialang.org/t/ann-regressiontables-jl-produces-publication-quality-regression-tables/7516/32 "2018-01-22T11:29:20Z")

</div>

Thank you for your suggestion. Maybe it is not a very advanced thing to do, but I don’t have any idea how to do this.

Let’s say I have an adjusted vcov from `CovarianceMatrices.jl` also a DataFrameRegressionModel from `GLM.jl`. How do I pass the adjusted vcov matrix to `regtable()` then? An explanation involving `FixedEffectModels.jl` would be just as good.

I am working on an empirical paper right now and printing regression tables automatically would save be a considerable amount of time and also decrease the likelihood of errors on my behalf.

Thanks a lot!

---

<div class="post-metadata">

### Author: ![jmboehm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jmboehm/32/2263_2.png) [@jmboehm](https://discourse.julialang.org/u/jmboehm)
#### Post date: [January 23, 2018, 1:37am UTC](https://discourse.julialang.org/t/ann-regressiontables-jl-produces-publication-quality-regression-tables/7516/33 "2018-01-23T01:37:40Z")

</div>

Just create a new `RegressionResultFE` with your adjusted VCov matrix, e.g.

```julia
using RegressionTables, DataFrames, FixedEffectModels, RDatasets

df = dataset("datasets", "iris")
df[:SpeciesDummy] = pool(df[:Species])

rr1 = reg(df, @model(SepalLength ~ SepalWidth , fe = SpeciesDummy))

mynewvcovmatrix = Array{Float64,2}(1,1)
mynewvcovmatrix[1,1]=1.0

myrr = RegressionResultFE(rr1.coef, mynewvcovmatrix, rr1.esample, rr1.augmentdf, rr1.coefnames, rr1.yname, rr1.formula, rr1.feformula, rr1.nobs, rr1.df_residual, rr1.r2, rr1.r2_a, rr1.r2_within, rr1.F, rr1.p, rr1.iterations, rr1.converged)

regtable(myrr)

```

or similarly with whatever result struct you’re using.

---

<div class="post-metadata">

### Author: ![IljaK91](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/iljak91/32/44301_2.png) [@IljaK91](https://discourse.julialang.org/u/IljaK91)
#### Post date: [January 23, 2018, 10:39am UTC](https://discourse.julialang.org/t/ann-regressiontables-jl-produces-publication-quality-regression-tables/7516/34 "2018-01-23T10:39:30Z")

</div>

I am sorry that I am bothering you again with this, but it looks like `CovarianceMatrices.jl` is not working with the regression results of RegressionResultFE.

My code is:

```julia
using RegressionTables, DataFrames, FixedEffectModels, RDatasets, CovarianceMatrices

df = dataset("datasets", "iris")
df[:SpeciesDummy] = pool(df[:Species])

rr1 = reg(df, @model(SepalLength ~ SepalWidth , fe = SpeciesDummy))

mynewvcovmatrix = vcov(rr1, QuadraticSpectralKernel(NeweyWest))

myrr = RegressionResultFE(rr1.coef, mynewvcovmatrix, rr1.esample, rr1.augmentdf, rr1.coefnames, rr1.yname, rr1.formula, rr1.feformula, rr1.nobs, rr1.df_residual, rr1.r2, rr1.r2_a, rr1.r2_within, rr1.F, rr1.p, rr1.iterations, rr1.converged)

regtable(myrr)

```

The error message I get is

```julia

MethodError: no method matching vcov(::FixedEffectModels.RegressionResultFE, ::CovarianceMatrices.QuadraticSpectralKernel{CovarianceMatrices.Optimal{CovarianceMatrices.NeweyWest},CovarianceMatrices.#k_qs})
Closest candidates are:
  vcov(!Matched::DataFrames.DataFrameRegressionModel, ::CovarianceMatrices.HAC{CovarianceMatrices.Optimal{T<:CovarianceMatrices.OptimalBandwidth}}; args...) where T<:CovarianceMatrices.OptimalBandwidth at C:\Users\Ilja\.julia\v0.6\CovarianceMatrices\src\HAC.jl:235
  vcov(!Matched::Union{DataFrames.DataFrameRegressionModel, DataFrames.DataFrameStatisticalModel}, ::Any...; kwargs...) at C:\Users\Ilja\.julia\v0.6\DataFrames\src\statsmodels\statsmodel.jl:27
  vcov(::FixedEffectModels.AbstractRegressionResult) at C:\Users\Ilja\.julia\v0.6\FixedEffectModels\src\RegressionResult.jl:13
  ...

```

---

<div class="post-metadata">

### Author: ![jmboehm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jmboehm/32/2263_2.png) [@jmboehm](https://discourse.julialang.org/u/jmboehm)
#### Post date: [January 23, 2018, 6:26pm UTC](https://discourse.julialang.org/t/ann-regressiontables-jl-produces-publication-quality-regression-tables/7516/35 "2018-01-23T18:26:12Z")

</div>

Estimate your model and construct your adjusted covariance matrix in any way that works for you. Then fill it into a structure that is supported by `RegressionTables`, i.e. the structures from `FixedEffectModels.jl` (which you can find in src/RegressionResult.jl) or `GLM.jl`. In my example above the structure is `RegressionResultFE`, but there are several others.

PM or email me if it’s still not clear.

---

<div class="post-metadata">

### Author: ![Yifan\_Liu](https://avatars.discourse-cdn.com/v4/letter/y/4da419/32.png) [@Yifan\_Liu](https://discourse.julialang.org/u/Yifan_Liu)
#### Post date: [September 22, 2019, 4:49pm UTC](https://discourse.julialang.org/t/ann-regressiontables-jl-produces-publication-quality-regression-tables/7516/36 "2019-09-22T16:49:51Z")

</div>

I am using RegressionTables v0.2.2 on Julia Version 1.1.0

```julia
using RegressionTables
[Info: Precompiling RegressionTables [d519eb52-b820-54da-95a6-98e1306fdade]
WARNING: could not import FixedEffectModels.FixedEffectModel into RegressionTables
WARNING: could not import FixedEffectModels.has_fe into RegressionTables
WARNING: could not import FixedEffectModels.has_iv into RegressionTables
WARNING: could not import StatsModels.TableRegressionModel into RegressionTables
ERROR: LoadError: LoadError: UndefVarError: FixedEffectModel not defined

```

---

<div class="post-metadata">

### Author: ![jmboehm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jmboehm/32/2263_2.png) [@jmboehm](https://discourse.julialang.org/u/jmboehm)
#### Post date: [September 25, 2019, 10:44pm UTC](https://discourse.julialang.org/t/ann-regressiontables-jl-produces-publication-quality-regression-tables/7516/37 "2019-09-25T22:44:57Z")

</div>

The tests pass on Julia 1.1 for 0.2.2 and for the new version which I just pushed onto master. Which version of FixedEffectModels are you using? Does it happen from a fresh session?

---

<div class="post-metadata">

### Author: ![Yifan\_Liu](https://avatars.discourse-cdn.com/v4/letter/y/4da419/32.png) [@Yifan\_Liu](https://discourse.julialang.org/u/Yifan_Liu)
#### Post date: [September 26, 2019, 8:18pm UTC](https://discourse.julialang.org/t/ann-regressiontables-jl-produces-publication-quality-regression-tables/7516/38 "2019-09-26T20:18:43Z")

</div>

I am using FixedEffectModels v0.7.4. I think some other packages forced it to the old version. It seems I cannot update it to the newest version.

---

<div class="post-metadata">

### Author: ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)
#### Post date: [September 26, 2019, 8:32pm UTC](https://discourse.julialang.org/t/ann-regressiontables-jl-produces-publication-quality-regression-tables/7516/39 "2019-09-26T20:32:17Z")

</div>

This happened to me yesterday as well, but I was only using GLM.

---

<div class="post-metadata">

### Author: ![jmboehm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jmboehm/32/2263_2.png) [@jmboehm](https://discourse.julialang.org/u/jmboehm)
#### Post date: [September 26, 2019, 8:55pm UTC](https://discourse.julialang.org/t/ann-regressiontables-jl-produces-publication-quality-regression-tables/7516/40 "2019-09-26T20:55:54Z")

</div>

v0.2.2 requires FixedEffectModels 0.8.2 at least. Thanks for alerting me to this, it’s now required in Project.toml.

[Previous page](https://discourse.julialang.org/t/ann-regressiontables-jl-produces-publication-quality-regression-tables/7516.md?page=1)

[Next page](https://discourse.julialang.org/t/ann-regressiontables-jl-produces-publication-quality-regression-tables/7516.md?page=3)
