Closed turbanisch closed 5 months ago
Hi, actually this is perfectly normal since, once out of the function, the data set does not exist anymore.
You can try with lm
you would get the same error.
That said, with the new argument data.save
, it will work:
fit_model <- function(df) {
fepois(Euros ~ log(dist_km) | Origin + Destination,
data = df, data.save = TRUE)
}
mod2 <- fit_model(trade)
# try to update
update(mod2, . ~ . + log(Year))
#> Poisson estimation, Dep. Var.: Euros
#> Observations: 38,325
#> Fixed-effects: Origin: 15, Destination: 15
#> Standard-errors: Clustered (Origin)
#> Estimate Std. Error z value Pr(>|z|)
#> log(dist_km) -1.51756 0.113171 -13.4095 < 2.2e-16 ***
#> log(Year) 72.36888 6.899699 10.4887 < 2.2e-16 ***
#> ---
#> Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
#> Log-Likelihood: -1.212e+12 Adj. Pseudo R2: 0.592897
#> BIC: 2.424e+12 Squared Cor.: 0.384441
Apparently the
update()
method cannot retrieve the dataset the estimation was based on if I wrap the estimation function in another function. Is there any way around this?Created on 2023-02-26 with reprex v2.0.2