Introductory Econometrics - Jeffrey M. Wooldridge: Como replicar os exemplos do Capítulo 7 usando python?

+2 votos
396 visitas
perguntada Fev 19, 2016 em Economia

1 Resposta

0 votos
respondida Fev 19, 2016 por (5,581 pontos)

Example 7.1:

import numpy as np
import statsmodels.api as sm
import matplotlib as plt
import pandas as pd
import patsy as ps

# Ex. 7.1

if __name__ == '__main__':

'services','profserv','profocc','clerocc','servocc','lwage','expersq','tenursq']

# Model 1
y,X = ps.dmatrices('wage ~ female + educ + exper + tenure',data=df, return_type='dataframe')
model = sm.OLS(y,X) # Describe Model
results = model.fit() # Fit model
print results.summary()

# Model 2
y,X = ps.dmatrices('wage ~ female',data=df, return_type='dataframe')
model = sm.OLS(y,X) # Describe Model
results = model.fit() # Fit model
print results.summary()


Example 7.6

import numpy as np
import statsmodels.api as sm
import matplotlib as plt
import pandas as pd
import patsy as ps

# Ex. 7.6

if __name__ == '__main__':

'services','profserv','profocc','clerocc','servocc','lwage','expersq','tenursq']

# Model 1
y,X = ps.dmatrices('wage ~ female + educ + exper + tenure',data=df, return_type='dataframe')
model = sm.OLS(y,X) # Describe Model
results = model.fit() # Fit model
print results.summary()

df['marrmale']=(1-df['female']) *df['married']
df['marrfem']=df['female'] *df['married']
df['singfem']=df['female'] *(1-df['married'])

# Model 2
y,X = ps.dmatrices('np.log(wage) ~ marrmale + marrfem + singfem + educ + exper + np.power(exper,2) + tenure + np.power(tenure,2)',data=df, return_type='dataframe')
model = sm.OLS(y,X) # Describe Model
results = model.fit() # Fit model
print results.summary()


Example 7.8:

import numpy as np
import statsmodels.api as sm
import matplotlib as plt
import pandas as pd
import patsy as ps

# Ex. 7.1

if __name__ == '__main__':