{smcl}
{* 15dec2005}{...}
{hline}
help for {hi:quaids_delta2}
{hline}

{title:One small step in demand system estimation}

{p 8 14 2}{cmd:quaids_delta2} {cmd:,} {cmdab:eq:uations(}{it:#}{cmd:)}


{title:Description}

{pstd}
{cmd:quaids_delta2} computes the derivative matrix required to implement 
the delta method when fitting an almost ideal demand system (AIDS).  
Since expenditure shares sum to one, the covariance matrix of the 
regression errors is singular.  Therefore, one equation is dropped 
before estimating the parameters and their covariance matrix.  The delta 
method is then used to obtain the full covariance matrix, including the 
covariance terms for the parameters of the dropped equation.

{pstd}
For more information on demand system estimation in Stata, see Poi 
(2002).  {cmd:quaids_delta2} supplants the {cmd:quaids_delta} program 
discussed there, and demand systems with any number of equations can now 
be fitted.

{pstd}
The matrix is returned in {cmd:r(Delta)}.


{title:Options}

{phang}
{opt equations(#)} specifies the number of expenditure share equations 
in the model (including the one dropped during estimation).


{title:Example}

{pstd}use data, clear{p_end}
{pstd}glo A_NOT = 6{p_end}
{pstd}glo NEQN = 7{p_end}

{pstd}ml model d0 lnl_quaids  (){space 2}/a2 /a3 /a4 /a5 /a6{space 12}/*{p_end}
{pstd}{space 8}*/{space 12}      /b1 /b2 /b3 /b4 /b5 /b6{space 12}/*{p_end}
{pstd}{space 8}*/{space 12}      /g11 /g21 /g31 /g41 /g51 /g61{space 6}/*{p_end}
{pstd}{space 8}*/{space 12}      /g22 /g32 /g42 /g52 /g62{space 11}/*{p_end}
{pstd}{space 8}*/{space 12}      /g33 /g43 /g53 /g63{space 16}/*{p_end}
{pstd}{space 8}*/{space 12}      /g44 /g54 /g64{space 21}/*{p_end}
{pstd}{space 8}*/{space 12}      /g55 /g65{space 26}/*{p_end}
{pstd}{space 8}*/{space 12}      /g66 {space 30}/*{p_end}
{pstd}{space 8}*/{space 12}      /l1 /l2 /l3 /l4 /l5 /l6

{pstd}ml max{p_end}

{pstd}matrix b = e(b){p_end}
{pstd}quaids_vec b theta{p_end}
{pstd}quaids_delta2, eq($NEQN){p_end}
{pstd}matrix r = r(Delta){p_end}
{pstd}matrix var = e(V){p_end}
{pstd}matrix var = r*var*r'{p_end}

{pstd}forv i = 1/$NEQN {{p_end}
{pstd}{space 8}glo anames "$anames alpha:`i'"{p_end}
{pstd}{space 8}glo bnames "$bnames beta:`i'"{p_end}
{pstd}{space 8}glo lnames "$lnames lambda:`i'"{p_end}
{pstd}{space 8}forv j = `i'/$NEQN {{p_end}
{pstd}{space 8}{space 8}glo gnames "$gnames gamma:`j'`i'"{p_end}
{pstd}{space 8}}{p_end}
{pstd}}{p_end}
{pstd}glo names "$anames $bnames $gnames $lnames"{p_end}
{pstd}matrix colnames theta = $names{p_end}
{pstd}matrix colnames var = $names{p_end}
{pstd}matrix rownames var = $names{p_end}

{pstd}program postit, eclass{p_end}

{pstd}{space 8}ereturn post theta var{p_end}

{pstd}end{p_end}
{pstd}postit{p_end}

{pstd}ereturn display{p_end}


{title:Also see}

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


