# Smoother Derivations of Hicksian Demands in Sage

The problem I'm solving is an economics one relating to solving for hicksian demands,given my difficulty solving for them directly, Im trying to tackle this same problem indirectly and it works for the most part however I'd like it to run smoother.

Setting up the problem we have:

x1, x2, l, p1, p2, a, b,  R= var('x1, x2, l, p1, p2, a, b,  R')
U = x1^a*x2^b
m = p1*x1+p2*x2;
L = U+ l * (R-m);
dLdx = L.diff(x1);
dLdy = L.diff(x2);
dLdl = L.diff(l);
solve([dLdx == 0, dLdy == 0, dLdl == 0], x1, x2, l)

Out: [[x1 == R*a/((a + b)*p1), x2 == R*b/((a + b)*p2), l == (a + b)*(R*a/((a + b)*p1))^a*(R*b/((a + b)*p2))^b/R]]


I then manually plug in the values for $x_1$ and and $x_2$ into $U$ to get the indirect utility function and solve for the expenditure function:

 expend=solve(U==(R*a/((a + b)*p1))^a*(R*b/((a + b)*p2)^b),R);expend
Out: [R == ((a + b)*p2)^b*x1^a*x2^b/(b*(R*a/((a + b)*p1))^a)]


I again need to plug in this exact functional form to get the hicksian demands using shephard's lemma:

expend1=((a + b)*p2)^b*x1^a*x2^b/(b*(R*a/((a + b)*p1))^a)
expend1.diff(p1) #the hicksian demand for x1
Out:  ((a + b)*p2)^(b - 1)*(a + b)*x1^a*x2^b/(R*a/((a + b)*p1))^a

expend1.diff(p2) #the hicksian demand for x2
Out: ((a + b)*p2)^(b - 1)*(a + b)*x1^a*x2^b/(R*a/((a + b)*p1))^a


I'm interested in getting my code to run more parsimoniously as I find myself having to manually pull out solved values to move to next stages of the problem. This is frustrating because I'd have to do this each time if i change my functional form.

Note: I see that this method actually does not work as I didnt notice R on the Left hand side of this problem.

edit retag close merge delete

Sort by » oldest newest most voted

Thanks to Juanjo's answer to my question here I've managed to get a script which gives us an analytical solution for our hicksian demand equations. This is:

x1, x2, l, p1, p2, a, b,  R= var('x1, x2, l, p1, p2, a, b,  R')
U = x1^a*x2^b
m = p1*x1+p2*x2;
L = m+ l * (R-U);
dLdx = L.diff(x1);
dLdy = L.diff(x2);
dLdl = L.diff(l);
step1=solve([dLdx == 0, dLdy == 0, dLdl == 0], p1, p2, R)
step2=solve((p1/p2).subs(step1)==p1/p2, x1)
good2step3 = solve((U/R).subs(step2).log().log_expand()==0, x2)


where good1step4 is our hicksiand demand for $x_1$ and good2step3 is our hicksian demand for $x_2$.

Its interesting how you need a different procedure when your constraint is non-linear.

more

This answer may be relevant : the "manual" solution proposed can be programmed (although the relevant simplifications may vary). Sage will give you a mathematically sound solution, that you may have to simplify "manually" (easy with Sage's help...).

more