Closed erineidschun closed 5 years ago
Also stuck on Q1. My approach:
def foc(l_i_t):
return (.7 * np.exp(gamma_i + rho*w_i_tminus1 + .7*l_i_t + .3 * k_i_t + .5 * sigma2epsilon) - np.exp(l_i_t + w_i_t))
l_star = scipy.optimize.fsolve(foc,np.ndarray([1]))[0]
(also tried l_star = scipy.optimize.fsolve(foc,8)[0])
but the estimates I'm getting are unstable - every time I run the code, even with the same initial guess, I'm getting different answers. Is this an issue with the way I've set up the call of scipy.optimize.fsolve?
Hi @erineidschun . Your error means that your variables is not a number, but a sequence
. That is, it's maybe a list, tuple, numpy.ndarray
, etc.
Another issue, is that your first-order condition is not right. The equation that you have coded is the analytical solution for labor. The first-order condition is the one that starts looks like this:
[βππ‘:].7exp(πΎπ+πππ,π‘β1+.7βππ‘+.3πππ‘+12π2π)βexp(βππ‘+π€ππ‘)=0.
@richard-archer . This is a good point to bring up. Because of the shape of the FOC, the default algorithm for fsolve
has trouble when the initial value is too low. We can maybe see this by exploring the shape of the FOC. Here's some code to do it:
import ipywidgets
def plot_foc(gamma_i = 1.0, L_omega_it = -1.0, k_it = 1.0, w_it = -1.):
'''
Produce a plot of the foc and the zero line.
'''
f = lambda l: .7 * np.exp(gamma_i + rho * L_omega_it + .7 * l + .3 * k_it + .5 * (sigma2epsilon)) - np.exp(l + w_it)
vf = np.vectorize(f)
labor = np.linspace(-2,10,100)
plt.plot(labor, vf(labor))
plt.plot(labor, 0*labor)
plt.ylim([-1,3])
plt.xlabel('labor')
plt.ylabel('foc(labor) = 0');
ipywidgets.interact(plot_foc);
It produces something that looks like this:
My suggestion is to just use a very large value for the initial labor value. I use 50.0.
Thank you! That solves my issue with unstable identification/inability to identify.
Ah I see what I did wrong now, thank you!
On another note, I am having a problem with the fixed effects model in Q8:
df2 = df.dropna() reg_fixedeff = linearmodels.PanelOLS.from_formula("y ~ a + l + k + w + EntityEffects + TimeEffects", data=df2) reg_fitted = reg_fixedeff.fit() reg_fitted
my regression summary indicates that l and k are 100% accurately estimated (had the exact coefficients), so I think I may have done something wrong in gathering df, where df = create_DF(all_data) <--- your given code.
Ok. Don't include a
. This is meant to be unobserved. Check the rest of your regressors too. I have limited connectivity, so I can't check this out for sure.
I keep getting an error when using the fsolve function for Q1.
My code:
Error points to fsolve: TypeError: can't multiply sequence by non-int of type 'float'
I am not sure what I am doing wrong here? I checked and all the variables in funct are recognized as floats.