0
$\begingroup$

I'd like to perform a mediation analysis in Python and have done the following so far.

import pandas as pd
from linearmodels import PanelOLS
import statsmodels.api as sm2
from statsmodels.stats.mediation import Mediation

##1. direct effect: X --> Y
DV_LF = df.Y
IV_X = sm2.add_constant(df[['X', 'Control']])
fe_mod_X = PanelOLS(DV_LF, IV_X, entity_effects=True )
fe_res_X = fe_mod_X.fit(cov_type='clustered', cluster_entity=True)
print(fe_res_X)

##2. X --> M
DV_A = df.M
IV_A = sm2.add_constant(df[['X', 'Control']])
fe_mod_A = PanelOLS(DV_A, IV_A, entity_effects=True )
fe_res_A = fe_mod_A.fit(cov_type='clustered', cluster_entity=True)
print(fe_res_A)

##3. M --> Y
IV_M = sm2.add_constant(df[['M', 'Control']])
fe_mod_M = PanelOLS(DV_LF, IV_M, entity_effects=True )
fe_res_M = fe_mod_M.fit(cov_type='clustered', cluster_entity=True)
print(fe_res_M)

##4. X, M --> Y
IV_T = sm2.add_constant(df[['X', 'M', 'Control']])
fe_mod_T = PanelOLS(DV_LF, IV_T, entity_effects=True )
fe_res_T = fe_mod_T.fit(cov_type='clustered', cluster_entity=True)
print(fe_res_T)

from several posts like that one I understood, that the next step would be to test the null hypothesis that the indirect effect is 0 using bootstrapping on the CI. I did not understand how that would be done for my example. I found a tutorial how to do that technically here but I'm not sure I understood the procedure. What are the two samples I'd use as an input? What exactly would be the result, so what CI would I be calculating? I'm a bit stuck here.

btw. this question partially overlaps with my previous question

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.