<jupyter_start><jupyter_text>Assignment 2 Structural Econometrics: Question 1 November 9, 2018  <NAME><jupyter_code>import pandas as pd
import math
import numpy as np
import matplotlib.pyplot as plt
import statsmodels.api as sm
from scipy.stats import norm
from statsmodels.sandbox.regression.gmm import GMM
from statsmodels.base.model import GenericLikelihoodModel
#load data into memory
data = pd.DataFrame(data = np.genfromtxt('ps2.dat', delimiter='  '), columns=['y','x1','x2','z'])

#summary statistics
print data.mean()<jupyter_output>y      0.568393
x1    42.537849
x2    12.286853
z      9.029880
dtype: float64<jupyter_text>Part a<jupyter_code>#fit a simple probit
probit_mod = sm.Probit(data['y'], sm.add_constant(data[['x1','x2']]),missing='drop')

probit_results = probit_mod.fit()
print probit_results.summary()<jupyter_output>Optimization terminated successfully.
         Current function value: 0.664055
         Iterations 4
                          Probit Regression Results                           
==============================================================================
Dep. Variable:                      y   No. Observations:                  753
Model:                         Probit   Df Residuals:                      750
Method:                           MLE   Df Model:                            2
Date:                Fri, 19 Oct 2018   Pseudo R-squ.:                 0.02882
Time:                        19:08:07   Log-Likelihood:                -500.03
converged:                       True   LL-Null:                       -514.87
                                        LLR p-value:                 3.590e-07
==============================================================================
                 coef    std err          z      P>|z|      [0.025      0.975]
-----------------------------[...]<jupyter_text>Part b<jupyter_code>#calculate marginal effects
probit_margeff = probit_results.get_margeff(at='mean',dummy=True)
print probit_margeff.summary()<jupyter_output>Probit Marginal Effects       
=====================================
Dep. Variable:                      y
Method:                          dydx
At:                              mean
==============================================================================
                dy/dx    std err          z      P>|z|      [0.025      0.975]
------------------------------------------------------------------------------
x1            -0.0036      0.002     -1.592      0.111      -0.008       0.001
x2             0.0408      0.008      4.907      0.000       0.025       0.057
==============================================================================<jupyter_text>For a woman of mean age and education, the marginal effect of an additional year of education on the probability of working is about 4.1%.   Part c<jupyter_code>#fit a simple logit
logit_mod = sm.Logit(data['y'], sm.add_constant(data[['x1','x2']]),missing='drop')

logit_results = logit_mod.fit()
print logit_results.summary()<jupyter_output>Optimization terminated successfully.
         Current function value: 0.664044
         Iterations 5
                           Logit Regression Results                           
==============================================================================
Dep. Variable:                      y   No. Observations:                  753
Model:                          Logit   Df Residuals:                      750
Method:                           MLE   Df Model:                            2
Date:                Fri, 19 Oct 2018   Pseudo R-squ.:                 0.02884
Time:                        19:12:32   Log-Likelihood:                -500.03
converged:                       True   LL-Null:                       -514.87
                                        LLR p-value:                 3.561e-07
==============================================================================
                 coef    std err          z      P>|z|      [0.025      0.975]
-----------------------------[...]
{'fraction_non_alphanumeric': 0.22770069375619426, 'fraction_numerical': 0.05550049554013875, 'mean_word_length': 1.5502210991787744, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '83081', 'license': 'MIT', 'n_tokens_mistral': 1169, 'n_tokens_neox': 982, 'n_words': 253, 'path': 'hw2/question1.ipynb', 'repo_name': 'yingzheng-econ/struct', 'size': '4043'}