Оценка импульсных характеристик SVAR с доверительными интервалами Монтекарло в statsmodels python - PullRequest
0 голосов
/ 06 марта 2020

Я действительно смущен этим. Я могу оценить последовательность SVAR для разных регионов и вычислить их функции импульсного отклика с асимметричными c стандартными ошибками. Однако, когда я пытаюсь вычислить стандартные ошибки с помощью симуляции Монте-Карло. Я получаю сообщение об ошибке `` 'NoneType' объект не может быть подписан ".

Я не понимаю, почему python выдает это сообщение об ошибке

svar_model_benchmark = {}
svar_estimates_benchmark = {}
svar_irf_benchmark = {}
svar_figures_benchmark = {}
svar_figures_benchmark_cum = {}

datos['cdmxnorte_pibsa_c'] = datos['cdmx_pibsa_c']
datos['cdmxsur_pibsa_c'] = datos['cdmx_pibsa_c']
datos['mexicooriente_pibsa_c'] = datos['mexico_pibsa_c']
datos['mexicoponiente_pibsa_c'] = datos['mexico_pibsa_c']
datos['veracruznorte_pibsa_c'] = datos['veracruz_pibsa_c']
datos['veracruzsur_pibsa_c'] = datos['veracruz_pibsa_c']  

datos = pd.DataFrame.from_dict(datos)
#datos.drop(index = '2000Q2', axis = 1, inplace = True)

svar_model_benchmark = {}
for reg in region_selection:
    if (reg == 'cdmx'):
        x_norte = datos[[f'{reg}norte_empsa_c', f'{reg}_pibsa_c', 'irate_sa']].dropna(inplace = True)
        x_sur = datos[[f'{reg}sur_empsa_c', f'{reg}_pibsa_c', 'irate_sa']].dropna(inplace = True)
        svar_model_benchmark[f'svar_{reg}norte'] = VAR(endog = x_norte[[f'{reg}norte_empsa_c', f'{reg}_pibsa_c']], 
                                                         exog = x_norte[['irate_sa']]) 
        svar_model_benchmark[f'svar_{reg}sur'] = VAR(endog = x_sur[[f'{reg}sur_empsa_c', f'{reg}_pibsa_c']], 
                                                         exog = x_sur[['irate_sa']])  
        svar_estimates_benchmark[f'est_{reg}norte'] = svar_model_benchmark[f'svar_{reg}norte'].fit(maxlags = 4, ic = 'aic')
        svar_irf_benchmark[f'irf_{reg}norte'] = svar_estimates_benchmark[f'est_{reg}norte'].irf(20)
        svar_figures_benchmark[f'irf_plot_{reg}norte'] = svar_irf_benchmark[f'irf_{reg}norte'].plot(orth = True, 
                                                    impulse = f'{reg}_pibsa_c', 
                                                    response = f'{reg}norte_empsa_c', stderr_type = 'mc')  
        plt.close()
        svar_estimates_benchmark[f'est_{reg}sur'] = svar_model_benchmark[f'svar_{reg}sur'].fit(maxlags = 4, ic = 'aic')
        svar_irf_benchmark[f'irf_{reg}sur'] = svar_estimates_benchmark[f'est_{reg}sur'].irf(20)        
        # We create separate graphs for different regions
        svar_figures_benchmark[f'irf_plot_{reg}sur'] = svar_irf_benchmark[f'irf_{reg}sur'].plot(orth = True, 
                                                    impulse = f'{reg}_pibsa_c', 
                                                    response = f'{reg}sur_empsa_c', stderr_type = 'mc')
        plt.close()
    elif (reg == 'mexico'): 
        x_oriente = datos[[f'{reg}oriente_empsa_c', f'{reg}_pibsa_c', 'irate_sa']].dropna(inplace = True)
        x_poniente = datos[[f'{reg}poniente_empsa_c', f'{reg}_pibsa_c', 'irate_sa']].dropna(inplace = True)
        svar_model_benchmark[f'svar_{reg}oriente'] = VAR(endog = x_oriente[[f'{reg}oriente_empsa_c', f'{reg}_pibsa_c']], 
                                                         exog = x_oriente[['irate_sa']]) 
        svar_model_benchmark[f'svar_{reg}poniente'] = VAR(endog = x_poniente[[f'{reg}poniente_empsa_c', f'{reg}_pibsa_c']], 
                                                         exog = x_poniente[['irate_sa']]) 
        svar_estimates_benchmark[f'est_{reg}oriente'] = svar_model_benchmark[f'svar_{reg}oriente'].fit(maxlags = 4, ic = 'aic')
        svar_irf_benchmark[f'irf_{reg}oriente'] = svar_estimates_benchmark[f'est_{reg}oriente'].irf(20)
        svar_figures_benchmark[f'irf_plot_{reg}oriente'] = svar_irf_benchmark[f'irf_{reg}oriente'].plot(orth = True, 
                                                    impulse = f'{reg}_pibsa_c', 
                                                    response = f'{reg}oriente_empsa_c', stderr_type = 'mc')  
        plt.close()
        svar_estimates_benchmark[f'est_{reg}poniente'] = svar_model_benchmark[f'svar_{reg}poniente'].fit(maxlags = 4, ic = 'aic')
        svar_irf_benchmark[f'irf_{reg}poniente'] = svar_estimates_benchmark[f'est_{reg}poniente'].irf(20)        
        # We create separate graphs for different regions
        svar_figures_benchmark[f'irf_plot_{reg}poniente'] = svar_irf_benchmark[f'irf_{reg}poniente'].plot(orth = True, 
                                                    impulse = f'{reg}_pibsa_c', 
                                                    response = f'{reg}poniente_empsa_c', stderr_type = 'mc')
        plt.close()
    elif (reg == 'veracruz'): 
        x_norte = datos[[f'{reg}norte_empsa_c', f'{reg}_pibsa_c', 'irate_sa']].dropna(inplace = True)
        x_sur = datos[[f'{reg}sur_empsa_c', f'{reg}_pibsa_c', 'irate_sa']].dropna(inplace = True)
        svar_model_benchmark[f'svar_{reg}norte'] = VAR(endog = x_norte[[f'{reg}norte_empsa_c', f'{reg}_pibsa_c']], 
                                                         exog = x_norte[['irate_sa']]) 
        svar_model_benchmark[f'svar_{reg}sur'] = VAR(endog = x_sur[[f'{reg}sur_empsa_c', f'{reg}_pibsa_c']], 
                                                         exog = x_sur[['irate_sa']], stderr_type = 'mc')  
        svar_estimates_benchmark[f'est_{reg}norte'] = svar_model_benchmark[f'svar_{reg}norte'].fit(maxlags = 4, ic = 'aic') 
        svar_irf_benchmark[f'irf_{reg}norte'] = svar_estimates_benchmark[f'est_{reg}norte'].irf(20)
        svar_figures_benchmark[f'irf_plot_{reg}norte'] = svar_irf_benchmark[f'irf_{reg}norte'].plot(orth = True, 
                                                    impulse = f'{reg}_pibsa_c', 
                                                    response = f'{reg}norte_empsa_c', stderr_type = 'mc') 
        plt.close()
        svar_estimates_benchmark[f'est_{reg}sur'] = svar_model_benchmark[f'svar_{reg}sur'].fit(maxlags = 4, ic = 'aic') 
        svar_irf_benchmark[f'irf_{reg}sur'] = svar_estimates_benchmark[f'est_{reg}sur'].irf(20)        
        # We create separate graphs for different regions
        svar_figures_benchmark[f'irf_plot_{reg}sur'] = svar_irf_benchmark[f'irf_{reg}sur'].plot(orth = True, 
                                                    impulse = f'{reg}_pibsa_c', 
                                                    response = f'{reg}sur_empsa_c')
        plt.close()
    else:
        x = datos[[f'{reg}_empsa_c', f'{reg}_pibsa_c', 'irate_sa']].dropna(inplace = True)
        svar_model_benchmark[f'svar_{reg}'] = VAR(endog = x[[f'{reg}_empsa_c', f'{reg}_pibsa_c']], 
                                                         exog = x[['irate_sa']]) 
        svar_estimates_benchmark[f'est_{reg}'] = svar_model_benchmark[f'svar_{reg}'].fit(maxlags = 4, ic = 'aic')
        svar_irf_benchmark[f'irf_{reg}'] = svar_estimates_benchmark[f'est_{reg}'].irf(20)
        svar_figures_benchmark[f'irf_plot_{reg}'] = svar_irf_benchmark[f'irf_{reg}'].plot(orth = True, 
                                                    impulse = f'{reg}_pibsa_c', 
                                                    response = f'{reg}_empsa_c', stderr_type = 'mc')    
        plt.close()

...