Skip to content

Commit 8933892

Browse files
committed
up
1 parent 8d81e39 commit 8933892

File tree

5 files changed

+31
-41
lines changed

5 files changed

+31
-41
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
2020

2121
[compat]
2222
DataFrames = "≥ 0.19.1"
23-
FixedEffectModels = "≥ 0.9.1"
23+
FixedEffectModels = "≥ 0.9.2"
2424
FixedEffects = "≥ 0.3.0"
2525
LeastSquaresOptim = "≥ 0.7.0"
2626
StatsBase = "≥ 0.22.0"

README.md

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@ The definition of interactive fixed effects follows Bai (2009).Formally, denote
99

1010
![minimization](img/minimization.png)
1111

12-
13-
14-
## Syntax
15-
Specify a formula with a way to compute standard errors with the argument `vcov`.
12+
## Formula Syntax
1613

1714
```julia
1815
using DataFrames, RDatasets, InteractiveFixedEffectModels
@@ -31,14 +28,19 @@ regife(df, @formula(Sales ~ Price + fe(State) + ife(State, Year, 2)))
3128
```
3229
A typical formula is composed of one dependent variable and a set of regressors.
3330
34-
Interactive fixed effects are indicated with the function `ife`. For instance, to specify a factor model with id variable `State`, time variable `Year`, and rank 2, use `ife(State, Year, 2)`.
31+
Interactive fixed effects are indicated with the function `ife`. For instance, to specify a factor model with id variable `State`, time variable `Year`, and rank 2, use `ife(State, Year, 2)`.
3532
36-
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
33+
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
3734
38-
```julia
39-
regife(df, @formula(Sales ~ Price + Year + ife(State, Year, 2)))
40-
regife(df, @formula(Sales ~ Price + Year + ife(State, Year, 2) + fe(State)))
41-
```
35+
```julia
36+
regife(df, @formula(Sales ~ Price + ife(State, Year, 2)))
37+
regife(df, @formula(Sales ~ Price + ife(State, Year, 2) + fe(State)))
38+
```
39+
40+
To construct formula programatically, you can use
41+
```julia
42+
regife(df, Term(:Sales) ~ Term(:Price) + ife(Term(:State), Term(:Year), 2) + fe(Term(:State)))
43+
```
4244
4345
4446
## Options
@@ -47,7 +49,7 @@ A typical formula is composed of one dependent variable and a set of regressors
4749
vcov.robust()
4850
vcov.cluster(:State)
4951
vcov.cluster(:State, :Year)
50-
```
52+
```
5153
- The option `weights` can add weights
5254
```julia
5355
weights = :Pop
@@ -64,22 +66,16 @@ A typical formula is composed of one dependent variable and a set of regressors
6466
- The option `save = true` saves a new dataframe storing residuals, factors, loadings and the eventual fixed effects. Importantly, the returned dataframe is aligned with the initial dataframe (rows not used in the estimation are simply filled with `missing`s).
6567
6668
67-
## Construct Model Programatically
68-
You can use
69-
```julia
70-
using StatsModels, DataFrames, RDatasets, InteractiveFixedEffectModels
71-
df = dataset("plm", "Cigar")
72-
regife(df, Term(:Sales) ~ Term(:NDI) + fe(Term(:State)) + ife(Term(:State), Term(:Year), 2), Vcov.cluster(:State))
73-
```
7469
70+
## FAQ
7571
7672
77-
## Local minimum vs global minimum
73+
#### Local minimum vs global minimum
7874
The algorithm can estimate models with missing observations per id x time, multiple observations per id x time, and weights.
7975
8076
However, in these cases, the optimization problem may have local minima. The algorithm tries to catch these cases, and, if need be, restart the optimization until the global minimum is reached. However I am not sure that all the cases are caught.
8177
82-
## FAQ
78+
8379
#### Does the package estimate PCA / factor models?
8480
8581
Yes. Factor models are a particular case of interactive fixed effect models.

src/InteractiveFixedEffectModels.jl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,8 @@ regife
4242
##
4343
##############################################################################
4444
include("types.jl")
45-
4645
include("methods/gauss_seidel.jl")
4746
include("methods/ls.jl")
48-
4947
include("fit.jl")
50-
48+
include("deprecated.jl")
5149
end

src/deprecated.jl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
3+
4+
function evaluate_subset(df, ex::Expr)
5+
if ex.head == :call
6+
return Expr(ex.head, ex.args[1], (evaluate_subset(df, ex.args[i]) for i in 2:length(ex.args))...)
7+
else
8+
return Expr(ex.head, (evaluate_subset(df, ex.args[i]) for i in 1:length(ex.args))...)
9+
end
10+
end
11+
evaluate_subset(df, ex::Symbol) = df[!, ex]
12+
evaluate_subset(df, ex) = ex

src/fit.jl

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@
44
## Fit is the only exported function
55
##
66
##############################################################################
7-
8-
9-
10-
117
function regife(df, m::FixedEffectModels.ModelTerm; kwargs...)
128
regife(df, m.f; m.dict..., kwargs...)
139
end
@@ -322,16 +318,4 @@ function regife(df, f::FormulaTerm, vcov::CovarianceEstimator = Vcov.simple();
322318
coef_names, yname, f, nobs, dof_residual, r2, r2_a, r2_within,
323319
rss, sum(iterations), all(converged))
324320
end
325-
end
326-
327-
328-
329-
function evaluate_subset(df, ex::Expr)
330-
if ex.head == :call
331-
return Expr(ex.head, ex.args[1], (evaluate_subset(df, ex.args[i]) for i in 2:length(ex.args))...)
332-
else
333-
return Expr(ex.head, (evaluate_subset(df, ex.args[i]) for i in 1:length(ex.args))...)
334-
end
335-
end
336-
evaluate_subset(df, ex::Symbol) = df[!, ex]
337-
evaluate_subset(df, ex) = ex
321+
end

0 commit comments

Comments
 (0)