{smcl}
{* 01sep2002}{...}
{hline}
help for {hi:demand systems}{right:(SJ2-4: st0029)}
{hline}


{title:Demand System Estimation in Stata}

{p 4 4 2} Currently Stata does not have any built-in commands to estimate
demand systems such as Deaton and Muellbauer's (1980) almost ideal demand
system (AIDS) or Banks, Blundell, and Lewbel's (1997) quadratic AIDS (QUAIDS)
model.  However, Poi (2002) discussed estimation using Stata's {cmd:ml}
commands.  Since you are reading this help file, the programs discussed in
that article are probably already installed on your system.

{p 4 4 2}These programs are intended to serve two purposes, both of which
require that you have a copy of the article.  First, they allow you to follow
the examples and discussion in the article and replicate those results.
Second, these programs can serve as templates for users who wish to estimate
their own demand systems.  If you are looking for a simple, ready-to-use
command to estimate demand equations without further programming, you are
looking in the wrong place.  Details of implementation will vary from model to
model, and so some degree of customization is required.

{p 4 4 2}The programs included with the article are

{p 8 8 2}lnl_quaids.ado{p_end}
{p 8 8 2}quaids.do{p_end}
{p 8 8 2}quaids_delta.ado{p_end}
{p 8 8 2}quaids_params.ado{p_end}
{p 8 8 2}quaids_vec.ado{p_end}
{p 8 8 2}vec_sum.ado{p_end}
{p 8 8 2}food.dta 

{p 4 4 2}Although no substitute for the original article, this help file
briefly discusses what those programs do and how to use them.  The program
{hi:quaids.do} reproduces the results shown in Poi (2002), and the file
{hi:food.dta} contains the household food consumption data used in that
article.

{p 4 4 2}At the heart of any maximum likelihood estimation exercise in Stata
is an ado-file which computes the likelihood; here the program
{hi:lnl_quaids.ado} accomplishes that task.  Since expenditure shares sum to
one, the covariance matrix for the entire system is identically singular.
Therefore, the last equation is dropped and the likelihood function is
calculated using the first K-1 equations only; Barten (1969) showed that it
makes no difference which equation is eliminated.  The parameters of the
dropped equation are recovered from the adding-up, homogeneity, and Slutsky
symmetry conditions.  This likelihood evaluator is of type d0 in Stata's
nomenclature, and so it receives just a scalar to be filled with the overall
log-likelihood, a vector containing the parameters, and a third argument which
can safely be ignored here.

{p 4 4 2}The program {hi:quaids_params.ado} takes a vector of parameters as
passed to lnl_quaids.ado and splits them up into the individual parameter
vectors alpha, beta, gamma, and lambda in which the actual QUAIDS model is
written.  This program also recovers the parameters for the dropped equation.
Program lnl_quaids.ado calls this program to get the real parameters and then
proceeds to estimate the residuals from the expenditure share equations,
estimate the covariance matrix, and finally compute the log-likelihood.
Program quaids_params.ado utilities {hi:vec_sum.ado} from time to time to
compute the sum of a vector.

{p 4 4 2}With the likelihood function set up, the next several steps are
similar to any other {cmd:ml} problem.  The main difference is that here we
want {cmd:ml} to pass a raw vector of parameters and do not want it to group
them into equations.  Therefore, we specify each parameter using the syntax
for equations containing only constants:

{p 8 8 2}
ml model d0 lnl_quaids () /a2 /a3 /b1 /b2 /b3 
   /g11 /g21 /g31 /g22 /g32 /g33 /l1 /l2 /l3
                    
{p 4 4 2}Note that {cmd:ml model} requires us to specify the first constant
using the () form and will not allow us to specify it as /a1.  After that the
{cmd:ml search} and {cmd:ml maximize, nooutput} commands can be issued to
actually find the maximum likelihood estimates.  The nooutput option is used
because we will display the output ourselves after we recover the parameters
and standard errors for the dropped equation.

{p 4 4 2} After {cmd:ml maximize} is finished, the next step is to recover the
parameters of the dropped equation; program {hi:quaids_vec.ado} does that.
This program differs from quaids_params.ado in that here we still get back
just a single vector of parameters, though it does include the parameters of
the dropped equation.  Getting the complete covariance matrix of the
parameters, including those of the dropped equation, is a straightforward
application of the delta method.  The program {hi:quaids_delta.ado} computes
the required Jacobian.  The details of implementing all of this are shown in
quaids.do and so are not repeated here.

{p 4 4 2}The final steps include providing column names to the parameter
vector and covariance matrix, reposting the results using {cmd:estimates
repost}, and finally displaying the results.  These steps are also detailed in
quaids.do.


{title:References}

{p 4 8 2}
Banks, J., R. Blundell, & A. Lewbel. 1997. Quadratic Engel curves and
consumer demand. {it:Review of Economics and Statistics} 69: 527--539.

{p 4 8 2}
Barten, A. 1969. Maximum likelihood estimation of a complete system of  
demand equations. {it:European Economic Review} 1: 7--73.

{p 4 8 2}
Deaton, A. & J. Muellbauer. 1980. An almost ideal demand system. 
{it:American Economic Review} 70: 312--326.

{p 4 8 2}
Poi, B. P. 2002. From the help desk: Demand system estimation. 
{it:Stata Journal} 2(4): 403--410 .
