Closed crisla closed 9 years ago
@crisla
When the variance of x is very small relative to variance of y, then the range of integration will be very narrow (i.e., solver will need to take very small steps). The optimal step size is being computed automatically by the solver so I think everything should work fine.
Can you be more specific? Which notebook contains the code you want me to look at? What distributions are you using for x and y? Uniform? Log-normal?
@crisla
My intuition is that as workers/land becomes increasingly homogenous (i.e., var x falls), then firms/farms are going to be increasingly homogenous in terms of size. This would suggest, given the distributions you are using, that as var x goes to zero, firm/farm size as a function of x should converge to a constant theta(x)=1.
However, the solver appears to be converging to a constant theta(x)=0
(roughly).
Note that I have terrible economic intuition...
What happened to all of the files in your branch? Where did inputs.py, models.py, solvers.py
go? You will need these for the code to work properly.
@davidrpugh
Woops, you are right, they were missing - I've pushed them now.
I've been looking at the model again. The differential equation of theta (farm/firm size) depends on the probability density function of x. When the distribution of x is degenerate, I would guess the derivative becomes messy and that can cause problems when evaluating it.
My economic intuition of this was:
k depends crucially on x. For the same x, farmers choose the same k. This is something that you see in the notebook and its fine.
Now, if (good) farmers want to maximize benefits, the only thing they can vary is labour. Labour becomes very important for farmers now, its derivative goes up, its price goes up (notice that the wage is between 8.59 and 17 in the poor country) and compare to the price of capital (0.83) they just substitute all workers for capital.
In this model, the price of capital is fixed, but labour is not - depends on the rest of the parameters. If for some reason the resulting wage compared to the price of capital is way too high, then firms/farmers are not going to hire anyone.
The fact that labour also goes down to zero without capital ruins somehow this explanation, and leaves me with the feeling that the differential equation system of this model can't handle homogeneity of x - because it depends on the derivative of the distribution of x.
@crisla
I am not sure that the model does break down: note that the solver is getting the limiting behavior of mu(x)
correct. Perhaps we should port over the residual and plotting residual methods so that we can better appreciate the amount of numerical error in the computed solutions?
Also talk to Philipp...remember Philipp thinks that model with homogenous workers/land should recover the solution to the Restuccia (sp?) paper.
I have added another notebook using Adamopoulos and Restuccia's parameters, and now it look better!
@davidrpugh
Update: in the branch introducing capital, I have added three new notebooks. They are related to the model in which x enters exponentially versus the classic version, where x multiplies k:
Classical Version - in Examples with Kx.ipynb Exponential Version - in Examples with K exp x.ipynb
The notebooks use the parameters of Adamopoulos and Restuccia(2014), with x almost constant.
Finally, New Capital.ipynb solves for capital as a function of other parameters (trigonometric approximation works fine) for the exponential case.
In both cases, the shooting solver says it terminates, but take a look at the errors!
I've tried at the end of both notebooks to create distributions from the solution. If you could check this it would be great - we can talk more about distributions somewhere else...
Quick doubt about the distributions:
I have built them using the wikipedia and they look good, but how do I scale them? I have something very big in the y axis and scaling them (so the integral adds up to one) is not trivial. Using normed=True
does not work.
@crisla
Setting normed=True
only insures that the pdf for the input is normalized correctly. I think you should only need to divide through the un-normalized density by theta_upper - theta_lower
.
@davidrpugh
I have added a notebook that solves for the same models without capital, just to check that the distribution of land looks exactly the same for both the rich and the poor country (so the only difference is that A is smaller int eh poor country. It just confirms that the solution of capital is not what it is producing the result - and all of that arcosines things are actually working fine!
At this point, the result can be done because maybe it is not the right model to replicate the original paper. I'm trying to read it, but Matlab code is so messy and weird. They have to define functions to approximate a log normal from the data by hand. Gee.
@davidrpugh
Quick update on this:
[In Examples with K exp x] The parameters in the case of the poor country are such that the solution for capital that I got was no longer valid, as the equation which gives the optimal value for capital has only one real root. Trying Philipp's original solution makes the solver fail, because can't raise negative numbers to a fractional power error creeps out again.
I found that using hyperbolic trigonometric equations (cosh and arcosh) works well - I'm able to find the value of Fx, for example. That is, there not a math domain error here. But this time it is a question of the solver failing because it finds either a negative wage or a negative firm size.
What kind of problems can relate to a negative firm size error? I remember something about the production function must be super messed up to spit that error, but I'm pretty sure that this time I'm not misspecified the production function. I will keep trying with different starting guesses and integrators, and triple check that the optimal capital is the correct one - the one that appears in Hyper Capital. But if in the meantime you have any ideas of what could be happening, they would be most welcome!
@davidrpugh
I have an idea to solve for when the function of k* changes: approximate k*(x,y,l,r,params) with a polynomial! I bet it is a continuous function with a (hopefully small) kink at the point where the equation passes to have 3 roots. I will work on this in the capital notebook.
I just saw this, and I think that for this case, the approximation I have now works well enough to consider it done - for a fixed x=1.
@davidrpugh
In theory, what happens to the solver when the variance of x is very low, but the variance of y is large?
I have just uploaded the notebook I've been using to work with Philipp in the introducing-capital branch.
I get that labour goes down to something close to zero. I think is also not something that happens only with capital - in the examples notebook I tried to do the same with similar results. Maybe it is something about the model? Or is it something about the code?