Econometrics

Hal Varian
January 1992

Goodness of Fit

Let's see how to measure goodness-of-fit, using the Cobb-Douglas money metric utility function.  Recall that this function is given by:

m[p1_,p2_,x1_,x2_] := 2 p1^(1/2)p2^(1/2)x1^(1/2)x2^(1/2)

Let's generate some Cobb-Douglas demand data and perturb it by a random variable.  We'll fix income at 100 and p2 at 1, and let p1 range from 1 to 10.

x1Data=Table[N[100/(2 p1)],{p1,1,10}]
errorTerm=Table[Random[]/5,{p1,1,10}]
x1DataPerturbed=x1Data*(1+errorTerm)
x2Data=Table[100/2,{p1,1,10}]

We want to make sure that the budget constraint is satisfied by the perturbed data.  Hence we multiply the second demand by (1-errorTerm).  We check the budget constraint next, to make sure we've done it right.

x2DataPerturbed=x2Data*(1-errorTerm)
x1DataPerturbed*Table[p1,{p1,1,10}] + x2DataPerturbed

Now we can compute the goodness of fit measures.

Table[N[m[i,1,x1DataPerturbed[[i]],x2DataPerturbed[[i]]]],
 {i,1,10}]

Note how close the values are to full efficiency.  We can have quite large perturbations of the data, and still be pretty close to optimizing behavior.

Agricultural economics

Here we give a numerical example of the phenomenon described in the text.  We have a number of farmers who want to maximize profits

profit[p_,q_,Q_,K_,S_] := p Q K^(1/2)S^(1/2) - q K

profit[p,q,Q,K,S]

Solve for the profit-maximizing demand and output:

solution=Solve[D[profit[p,q,Q,K,S],K]==0,K][[1]]
K[p_,q_,Q_,S_] := Evaluate[K/.solution]
K[p,q,Q,S]
Y[p_,q_,Q_,S_] := Evaluate[
                  PowerExpand[Q K^(1/2)S^(1/2)/.solution]]
Y[p,q,Q,S]

(The PowerExpand operator puts the answer into a simpler form.)

Now we'll generate some data for farms with high-quality land (Q=10) and for farms with low-quality land (Q=2).   First we'll generate some prices:

nObs=100;
outputPrice=Table[Random[],{i,1,nObs}];
inputPrice=Table[Random[],{i,1,nObs}];
sunnyDays=Table[Random[],{i,1,nObs}];

highData=Transpose[{Log[K[outputPrice,inputPrice,10,sunnyDays]],
          Log[Y[outputPrice,inputPrice,10,sunnyDays]]}];
lowData=Transpose[{Log[K[outputPrice,inputPrice,2,sunnyDays]],
          Log[Y[outputPrice,inputPrice,2,sunnyDays]]}];

Now we'll fit the data for each quality of land separately.

Fit[highData,{1,logK},logK]
Fit[lowData,{1,logK},logK]

Notice that we get the same answer---something pretty close to the correct value of  0.5.  But now let's put the data together and try the same operation.

allData=Join[highData,lowData];
Fit[allData,{1,logK},logK]

Note the upward bias in the estimated parameter.  We can do a scatterplot to see what's happening.  The true production relationship is logY=logQ + logK/2, so we add this to the graph for Q=2 and Q=10.

lowPlot=ListPlot[lowData,PlotStyle->AbsolutePointSize[3],
        Epilog->{Line[{{5,Log[2]+5/2},{-10.0,Log[2]-10/2}}],
                 Line[{{5,Log[10]+5/2},{-10.0,Log[10]-10/2}}]}]
highPlot=ListPlot[highData,PlotStyle->AbsolutePointSize[5],
Epilog->{Line[{{5,Log[10]+5/2},{-10.0,Log[10]-10/2}}],
Line[{{5,Log[2]+5/2},{-10.0,Log[2]-10/2}}]}]
Show[{highPlot,lowPlot},{lowPlot,highPlot}]

Each true production function fits the  data well, but when we put the two sets of data together, the fitted regression line will be too steep.

Estimating the factor demand functions

Let's see if we can get better estimates by estimating the factor demand function  rather than the production function.    First we solve for the factor demand when the parameters of the production function are unknown.

profit[p_,q_,Q_,K_,S_] := p Q K^a S^b - q K
D[profit[p,q,Q,K,S],K]

Mathematica has difficulty solving this equation, since it wants to find all solutions,  not just the real solutions that we care about.  But if we solve it by hand, we find that
             Log[k] = (1/(1-a)) log(q/p) + constant + error term
 To run this regression we need a new variable, and we need to extract Log[K] from allData.  To extract Log[K], we Transpose the list of data and take the first list using Take[Transpose[allData,1]]].  Then we join this with the new variable we need

Remember, we have to have two copies of the prices...

priceRatio=Join[Log[outputPrice/inputPrice],
                Log[outputPrice/inputPrice]];
newData=Transpose[{priceRatio,
        Take[Transpose[allData],1][[1]]}];
Fit[newData,{1,logPratio},logPratio]

estimatedValueOfa= 1-(1/1.8993)

Note how this value is much closer to the true value of  0.5.  [By the way, all of these statements are statistical statements, so every now and then this won't be true.  Run through these calculations again if this happens to you...]

Diewert Cost function

Here is the unit cost function for a special cast of the Diewert cost function.  We want to determine the shape of the isoquants as a function of the parameters.  The most interesting parameter is the curvature parameter

Clear[b]
c[w1_,w2_,b_] := w1 + w2 +  2 b Sqrt[w1 w2]

The conditional factor demands are

h1[w1_,w2_,b_] := Evaluate[D[c[w1,w2,b],w1]]
h2[w1_,w2_,b_] := Evaluate[D[c[w1,w2,b],w2]]
{h1[w1,w2,b],h2[w1,w2,b]}

Normalize w2=1 and plot (h1,h2), letting w1 vary.  We'll let the parameter b vary from b=1 to b=10.

Do[
 ParametricPlot[{h1[w1,1,b],h2[w1,1,b]},{w1,0.1,200},
 PlotLabel->b,AspectRatio->Automatic,
 PlotRange->{{0,30},{0,30}}],
 {b,1,10}
 ]

From these diagrams it is easy to see that increasing b will tend to make the isoquantsflatter.