Fixest Walkthorugh¶
This notebook recreates the very informative vignette
by Laurent Berge and Grant McDermott, Fast Fixed-Effects Estimation: Short Introduction.
Please read the original vignette, what follows in this notebook is a demontration on how to use the Python API through arpoon.
import arpoon as ar
data = ar.rpytools.r_data.load("trade", "fixest")
data.head()
fixest = ar.rfixest.Fixest(data=data)
fixest
gravity_ols = fixest.feols(
"Euros ~ log(dist_km) | Origin + Destination + Product + Year"
)
gravity_ols
gravity_pois = fixest.fepois(
"Euros ~ log(dist_km) | Origin + Destination + Product + Year"
)
gravity_pois
gravity_pois_multi = fixest.fepois(
"Euros ~ log(dist_km) | csw0(Year, Destination, Origin)"
)
gravity_pois_multi
gravity_negbin = fixest.fenegbin(
"Euros ~ log(dist_km) | Origin + Destination + Product + Year"
)
gravity_negbin
fixest.coeftable(to_paguro=True)
fixest.etable("feols.0")
intpois._n_models())
pois.is_fixest_multi()
check = ar.rpytools.r_packages.r_fixest.etable([fixest._r_est()[0]])
check.colnames = ar.rpytools.ro.StrVector(["", "name"])
check
# r_fixest.etable(fixest_obj)
from arpoon.rpytools.convert_frame.mode.convert_r_2_pydf import rdataframe_2_pydf
check = r_fixest.etable(ro.rl("temp_abc"))
print(check)
fixest.coeftable()
gravity_pois.summary()
gravity_pois.summary(vcov="twoway")
# Clustering the standard-errors
gravity_pois.summary(vcov="~Product")
gravity_pois.summary(cluster="Product")
# Note that you can always cluster the standard errors,
# even when the estimation contained no fixed-effect:
gravity_simple = fixest.fepois("Euros ~ log(dist_km)")
gravity_simple.summary("~ Origin + Destination")
# Finally, the standard-errors can also be computed at estimation time,
# you simply need to add the vcov argument:
fixest.fepois("Euros ~ log(dist_km)", vcov = "~Product")
# Other estimation functions
gravity_ols = fixest.feols(
"log(Euros) ~ log(dist_km) | Origin + Destination + Product + Year"
)
gravity_ols
gravity_negbin = fixest.fenegbin(
"Euros ~ log(dist_km) | Origin + Destination + Product + Year",
)
gravity_negbin
Note: difference from the R package
So far we have saved our fixest objects in multiple variables named: gravity_negbin, gravity_ols, gravity_simple ...
We are now at the Viewing the results in R paragraph.
So far we have saved our fixest objects in multiple variables named: gravity_negbin, gravity_ols, gravity_simple ...
While one can call the etable function that is in arpoon, the Fixest object has been saving all the estimations we have run so far and we can run the .etable() method of the Fixest object, however…
fixest.etable()
As you can see these are all the models we have run. In order for the object to retain only the models we want we can use a parameter named "clear" when calling an estimation method:
# Other estimation functions
gravity_ols = fixest.feols(
"log(Euros) ~ log(dist_km) | Origin + Destination + Product + Year",
clear=True # <--- here
)
gravity_pois = fixest.fepois(
"Euros ~ log(dist_km) | Origin + Destination + Product + Year"
)
table = fixest.etable(
headers = ["Gaussian", "Poisson"],
print_output=True
)
table
res_multi = fixest.fepois(
"Euros ~ log(dist_km) | csw0(Year, Destination, Origin)",
clear=True
)
res_multi
tex_str = fixest.etable(
cluster="~ Origin + Destination",
tex=True
)
gravity_pois.fixef()