Comments (2)
Several things:
- Your model is misspecified. The varying slopes syntax should only appear in the fixed-effects slot, i.e. after the
|
. - You are effectively saying that the varying the slopes syntax (
| Region[MktExpenses]
) is the same as a full regular interaction with both parent terms (Region * MktExpenses
<=>Region + MktExpenses + Region:MktExpenses
). This is not correct. Varying slopes is equivalent to a nested interaction where there is only one parent term (Region / MktExpenses
<=>Region + Region:MktExpenses
).
Here's proof using your demo dataset:
library(fixest)
set.seed(123)
# Number of observations
n <- 10000
n_regions<-3
# Generate fake data
data <- data.frame(
Sales = NA,
MktExpenses = rnorm(n, mean = 50, sd = 10),
Region = sample(LETTERS[1:n_regions], n, replace = TRUE)
)
fe<-setNames(rnorm(n_regions, mean = 50, sd = 10), LETTERS[1:n_regions])
# Calculate sales
data$Sales <- data$MktExpenses+fe[data$Region]+(data$Region=='A')*data$MktExpenses+rnorm(n, mean = 0, sd = 2)
## these three models are all equivalent
m1 = feols(Sales ~ Region + Region:MktExpenses, data = data)
m2 = feols(Sales ~ Region/MktExpenses, data = data)
m3 = feols(Sales ~ 1 | Region[MktExpenses], data = data)
coef(m2)[4:6]
#> RegionA:MktExpenses RegionB:MktExpenses RegionC:MktExpenses
#> 2.0005741 0.9978691 1.0029734
fixef(m3)[[2]]
#> A B C
#> 2.0005741 0.9978691 1.0029734
Created on 2024-06-14 with reprex v2.1.0
The "interaction terms" section of the introductory vignette explains this all in some detail, so I would recommend taking a look at it next: https://lrberge.github.io/fixest/articles/fixest_walkthrough.html#interaction-terms
from fixest.
Thanks a lot Grant for your very detailed answer!
from fixest.
Related Issues (20)
- Suggestion to Update Citation File HOT 1
- feglm(family='poisson') seems to hang in cpp_demean() but femlm(family='poisson') does not? HOT 2
- Turn off standard error calculation HOT 1
- Issue with `Inf` in iplot HOT 1
- Unexpected `call_env` / `summary_flags` behaviour in model objects when called within a function. HOT 1
- Use modern regex engine
- Period markers in iplot HOT 1
- `group` argument ignored in `etable` when specified via `setFixest_etable`, cause seems to be `dreamerr:::check_arg_plus` HOT 2
- `fixest:::vcov_hetero_internal` resets small sample `adj` to N / (N-1) HOT 3
- Weights in `femlm` and `feNmlm` HOT 1
- Support resizebox for etable HOT 5
- Supporting interactions in second stage of 2SLS IV HOT 1
- Unexpected syntax change in 0.12.1: Multiple DV in IV estimation HOT 1
- FEGLM Adding one of the fixed effects as dummy gives different results than TWFE.
- compare models
- Unclear error message when using `i(bin = )`
- Common Pool Fitstat? HOT 1
- Inconsistencies in Printout of Interaction Terms
- coeftable presents iid se's HOT 2
- Separated coefficients estimated in Poisson model
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fixest.