RH1994
RH1994

Reputation: 37

Plot interaction in paneldata

I have run this regression without any problems and I get 4 coefficients, for each interaction between econ_sit and educ_cat. Econ_sit is a continous variable, and educ_cat is a categorical variable from 1-6. How can i plot the coefficients only for the interaction terms in a good way?

model_int_f <- felm(satis_gov_sc ~ econ_sit*factor(educ_cat) + factor(benefit) + econ_neth + age + gender + pol_sof
     | factor(wave) + factor(id) # Respondent and time fixed effects
     | 0          
     | id,        # Cluster standard errors on each respondent

     data = full1)

summary(model_int_f)

Call:
   felm(formula = satis_gov_sc ~ econ_sit * factor(educ_cat) + factor(benefit) +      econ_neth + age + gender + pol_sof | factor(wave) + factor(id) |      0 | id, data = full1) 

Residuals:
     Min       1Q   Median       3Q      Max 
-0.58468 -0.04464  0.00000  0.04728  0.78470 

Coefficients:
                             Estimate Cluster s.e. t value Pr(>|t|)    
econ_sit                    0.1411692    0.0603100   2.341  0.01928 *  
factor(educ_cat)2           0.0525580    0.0450045   1.168  0.24292    
factor(educ_cat)3           0.1229048    0.0576735   2.131  0.03313 *  
factor(educ_cat)4           0.1244146    0.0486455   2.558  0.01057 *  
factor(educ_cat)5           0.1245556    0.0520246   2.394  0.01669 *  
factor(educ_cat)6           0.1570034    0.0577240   2.720  0.00655 ** 
factor(benefit)2           -0.0030380    0.0119970  -0.253  0.80010    
factor(benefit)3            0.0026064    0.0072590   0.359  0.71957    
econ_neth                   0.0642726    0.0131940   4.871 1.14e-06 ***
age                         0.0177453    0.0152661   1.162  0.24512    
gender                      0.1088780    0.0076137  14.300  < 2e-16 ***
pol_sof                     0.0006003    0.0094504   0.064  0.94935    
econ_sit:factor(educ_cat)2 -0.0804820    0.0653488  -1.232  0.21816    
econ_sit:factor(educ_cat)3 -0.0950652    0.0793818  -1.198  0.23114    
econ_sit:factor(educ_cat)4 -0.1259772    0.0692072  -1.820  0.06877 .  
econ_sit:factor(educ_cat)5 -0.1469749    0.0654870  -2.244  0.02485 *  
econ_sit:factor(educ_cat)6 -0.1166243    0.0693709  -1.681  0.09279 .  
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 0.1161 on 11159 degrees of freedom
  (23983 observations deleted due to missingness)
Multiple R-squared(full model): 0.8119   Adjusted R-squared: 0.717 
Multiple R-squared(proj model): 0.00657   Adjusted R-squared: -0.4946 
F-statistic(full model, *iid*):8.557 on 5630 and 11159 DF, p-value: < 2.2e-16 
F-statistic(proj model): 55.38 on 17 and 5609 DF, p-value: < 2.2e-16 

This is what my data looks like:

$ id          : num  1 1 1 1 2 2 2 2 3 3 3 3
 $ wave        : chr  "2013" "2015" "2016" "2017" ...
 $ satis_gov_sc: num  0.5 0.4 0.4 0.6 0.6 0.5 0.6 0.7 0.7 0.7 ...
 $ econ_sit    : num  NA NA 0.708 0.75 0.708 ...
 $ educ_cat    : num  5 5 5 5 5 6 6 6 6 6 ...
 $ benefit     : num  3 3 3 3 3 3 3 3 3 3 ...
 $ econ_neth   : num  NA 0.6 0.6 0.7 0.7 0.5 0.4 0.6 0.8 0.7 ...
 $ age         : num  58 60 61 62 63 51 53 54 55 56 ...
 $ gender      : num  1 1 1 1 1 1 1 1 1 1 ...
 $ pol_sof     : num  1 1 1 0.8 1 1 1 1 0.8 1 ...

I've tried to run af simple plot_model with the following code:

plot_model(model_int_f, type = "pred", terms = c("econ_sit", "educ_cat"))

However I only get error because the felm function is not compatible with "pred":

Error in UseMethod("predict") : 
  no applicable method for 'predict' applied to an object of class "felm"

Any suggestions on how to plot the interaction terms?

Thanks in advance!

Upvotes: 0

Views: 356

Answers (1)

Otto K&#228;ssi
Otto K&#228;ssi

Reputation: 3083

felm does not have a predict method so it is not compatible with plot_model. You could use some other fixed effects library.

Here's an example using fixest. As you did not provide a sample of your data, I have used data(iris).

library(fixest); library(sjPlot)
    res = feols(Sepal.Length ~ Sepal.Width + Petal.Length:Species | Species, cluster='Species', iris)
    plot_model(res, type = "pred", terms = c("Petal.Length", "Species"))

Upvotes: 1

Related Questions