text_plain_output_1.png
from statsmodels.sandbox.regression import gmm

import numpy as np # linear algebra

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

data = pd.read_csv('/kaggle/input/comp-macro/data.csv')
data = data.dropna()

instrument_df = data[['cons_lagged1', 'interest_lagged_1', 'lagged_cons_growth']]
endog_df = data[['int_forward', 'cons_forward', 'PCE']]
endog, instrument = map(np.asarray, [endog_df, instrument_df])

def moment_consumption1(params, endog):
    beta, gamma = params
    r_forw1, c_forw1, c = endog.T
    err = beta * (1 + r_forw1) * np.power(c_forw1 / c, -gamma) - 1
    return err

dependant = np.ones(endog.shape[0])
mod1 = gmm.NonlinearIVGMM(dependant, endog, instrument, moment_consumption1, k_moms=4)
I = np.eye(3)
res_two_way = mod1.fit([1, -1], maxiter=2, inv_weights=I)