Skip to content

Commit 8777c2a

Browse files
committed
update to FE 0.6
1 parent be97d4b commit 8777c2a

File tree

3 files changed

+18
-18
lines changed

3 files changed

+18
-18
lines changed

Project.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "InteractiveFixedEffectModels"
22
uuid = "80307280-efb2-5c5d-af8b-a9c15821677b"
3-
version = "0.6.0"
3+
version = "0.6.1"
44

55
[deps]
66
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
@@ -26,7 +26,7 @@ StatsBase = "0"
2626
StatsModels = "0.6"
2727
Tables = "0"
2828
DataFrames = "0.19"
29-
FixedEffects = "0.4, 0.5"
29+
FixedEffects = "0.6"
3030
FixedEffectModels = "0.9, 0.10"
3131
LeastSquaresOptim = "0.7"
3232

README.md

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
[![Build Status](https://travis-ci.org/matthieugomez/InteractiveFixedEffectModels.jl.svg?branch=master)](https://travis-ci.org/matthieugomez/InteractiveFixedEffectModels.jl)
22
[![Coverage Status](https://coveralls.io/repos/matthieugomez/InteractiveFixedEffectModels.jl/badge.svg?branch=master&service=github)](https://coveralls.io/github/matthieugomez/InteractiveFixedEffectModels.jl?branch=master)
33

4+
## Installation
5+
The package is registered in the [`General`](https://github.com/JuliaRegistries/General) registry and so can be installed at the REPL with
6+
7+
`] add InteractiveFixedEffectModels`.
48

59
## Motivation
610
This package implements a novel, fast and robust algorithm to estimate interactive fixed effect models.
@@ -12,7 +16,7 @@ The definition of interactive fixed effects follows Bai (2009).Formally, denote
1216
```julia
1317
using DataFrames, RDatasets, InteractiveFixedEffectModels
1418
df = dataset("plm", "Cigar")
15-
regife(df, @formula(Sales ~ Price + fe(State) + ife(State, Year, 2)))
19+
regife(df, @formula(Sales ~ Price + ife(State, Year, 2) + fe(State)))
1620
# Linear Factor Model
1721
#================================================================
1822
#Number of obs: 1380 Degree of freedom: 199
@@ -34,8 +38,8 @@ regife(df, @formula(Sales ~ Price + fe(State) + ife(State, Year, 2)))
3438
- High-dimensional Fixed effects can be used, as in `fe(State)` but only for the variables specified in the factor model. See [FixedEffectModels.jl](https://github.com/matthieugomez/FixedEffectModels.jl) for more information
3539
3640
```julia
37-
regife(df, @formula(Sales ~ Price + ife(State, Year, 2)))
38-
regife(df, @formula(Sales ~ Price + ife(State, Year, 2) + fe(State)))
41+
regife(df, @formula(Sales ~ Price + ife(State, Year, 2)))
42+
regife(df, @formula(Sales ~ Price + ife(State, Year, 2) + fe(State)))
3943
```
4044
4145
To construct formula programatically, use
@@ -113,10 +117,3 @@ In presence of cross or time correlation beyond the factor structure, the estima
113117
- https://github.com/joidegn/FactorModels.jl : fits and predict factor models on matrices
114118
- https://github.com/madeleineudell/LowRankModels.jl : fits general low rank approximations on matrices
115119
- https://github.com/aaw/IncrementalSVD.jl: implementation of the backpropagation algorithm
116-
117-
## Install
118-
119-
```julia
120-
using Pkg
121-
Pkg.add("InteractiveFixedEffectModels")
122-
```

src/fit.jl

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,10 +87,13 @@ function regife(df, f::FormulaTerm, vcov::CovarianceEstimator = Vcov.simple();
8787
vcov_method_data = Vcov.materialize(view(df, esample,:), vcov)
8888

8989
# Compute weights
90-
sqrtw = Ones{Float64}(sum(esample))
91-
if has_weights
92-
sqrtw = convert(Vector{Float64}, sqrt.(view(df, esample, weights)))
93-
end
90+
# Compute weights
91+
if has_weights
92+
weights = Weights(convert(Vector{Float64}, view(df, esample, weights)))
93+
else
94+
weights = Weights(Ones{Float64}(sum(esample)))
95+
end
96+
sqrtw = sqrt.(values(weights))
9497
for a in FixedEffectModels.eachterm(formula.rhs)
9598
if has_fe(a)
9699
isa(a, InteractionTerm) && error("Fixed effects cannot be interacted")
@@ -111,7 +114,7 @@ function regife(df, f::FormulaTerm, vcov::CovarianceEstimator = Vcov.simple();
111114
has_fes_intercept = true
112115
end
113116
fes = FixedEffect[FixedEffectModels._subset(fe, esample) for fe in fes]
114-
feM = FixedEffectModels.AbstractFixedEffectSolver{Float64}(fes, sqrtw, Val{:lsmr})
117+
feM = FixedEffectModels.AbstractFixedEffectSolver{Float64}(fes, weights, Val{:lsmr})
115118
end
116119

117120

@@ -203,7 +206,7 @@ function regife(df, f::FormulaTerm, vcov::CovarianceEstimator = Vcov.simple();
203206
# y ~ x + γ1 x factors + γ2 x loadings
204207
# if not, this means fit! ended up on a a local minimum.
205208
# restart with randomized coefficients, factors, loadings
206-
newfeM = FixedEffectModels.AbstractFixedEffectSolver{Float64}(getfactors(fp, fs), sqrtw, Val{:lsmr})
209+
newfeM = FixedEffectModels.AbstractFixedEffectSolver{Float64}(getfactors(fp, fs), weights, Val{:lsmr})
207210
ym .= ym ./sqrtw
208211
FixedEffectModels.solve_residuals!(ym, newfeM, tol = tol, maxiter = maxiter)
209212
ym .= ym .* sqrtw

0 commit comments

Comments
 (0)