You are on page 1of 16

The Stata Journal

Editors
H. Joseph Newton Nicholas J. Cox
Department of Statistics Department of Geography
Texas A&M University Durham University
College Station, Texas Durham, UK
editors@stata-journal.com editors@stata-journal.com

Associate Editors
Christopher F. Baum, Boston College Frauke Kreuter, Univ. of Maryland–College Park
Nathaniel Beck, New York University Peter A. Lachenbruch, Oregon State University
Rino Bellocco, Karolinska Institutet, Sweden, and Jens Lauritsen, Odense University Hospital
University of Milano-Bicocca, Italy Stanley Lemeshow, Ohio State University
Maarten L. Buis, WZB, Germany J. Scott Long, Indiana University
A. Colin Cameron, University of California–Davis Roger Newson, Imperial College, London
Mario A. Cleves, University of Arkansas for Austin Nichols, Urban Institute, Washington DC
Medical Sciences Marcello Pagano, Harvard School of Public Health
William D. Dupont, Vanderbilt University Sophia Rabe-Hesketh, Univ. of California–Berkeley
Philip Ender, University of California–Los Angeles J. Patrick Royston, MRC Clinical Trials Unit,
David Epstein, Columbia University London
Allan Gregory, Queen’s University Philip Ryan, University of Adelaide
James Hardin, University of South Carolina Mark E. Schaffer, Heriot-Watt Univ., Edinburgh
Ben Jann, University of Bern, Switzerland Jeroen Weesie, Utrecht University
Stephen Jenkins, London School of Economics and Nicholas J. G. Winter, University of Virginia
Political Science Jeffrey Wooldridge, Michigan State University
Ulrich Kohler, WZB, Germany

Stata Press Editorial Manager Stata Press Copy Editors
Lisa Gilmore David Culwell and Deirdre Skaggs

The Stata Journal publishes reviewed papers together with shorter notes or comments, regular columns, book
reviews, and other material of interest to Stata users. Examples of the types of papers include 1) expository
papers that link the use of Stata commands or programs to associated principles, such as those that will serve
as tutorials for users first encountering a new field of statistics or a major new technique; 2) papers that go
“beyond the Stata manual” in explaining key features or uses of Stata that are of interest to intermediate
or advanced users of Stata; 3) papers that discuss new commands or Stata programs of interest either to
a wide spectrum of users (e.g., in data management or graphics) or to some large segment of Stata users
(e.g., in survey statistics, survival analysis, panel analysis, or limited dependent variable modeling); 4) papers
analyzing the statistical properties of new or existing estimators and tests in Stata; 5) papers that could
be of interest or usefulness to researchers, especially in fields that are of practical importance but are not
often included in texts or other journals, such as the use of Stata in managing datasets, especially large
datasets, with advice from hard-won experience; and 6) papers of interest to those who teach, including Stata
with topics such as extended examples of techniques and interpretation of results, simulations of statistical
concepts, and overviews of subject areas.

The Stata Journal is indexed and abstracted by CompuMath Citation Index, Current Contents/Social and Behav-
ioral Sciences, RePEc: Research Papers in Economics, Science Citation Index Expanded (also known as SciSearch,
Scopus, and Social Sciences Citation Index.

For more information on the Stata Journal, including information for authors, see the webpage

http://www.stata-journal.com

com/bookstore/sjj. nor for special. or StataCorp. Mata. College Station. datasets. data. there is no warranty of fitness of purpose or merchantability.com. electronic version (ISSN 1536-8734) is a publication of Stata Press. StataCorp. 4905 Lakeway Drive. http://www. Address changes should be sent to the Stata Journal. ® Copyright  c 2012 by StataCorp LP Copyright Statement: The Stata Journal and the contents of the supporting files (programs. Stata Press. College Station. the author.stata. U. In particular. as long as any copy or reproduction includes attribution to both (1) the author and (2) the Stata Journal. ideas. or other locations where the copy may be accessed by anyone other than the subscriber. fileservers. incidental.com/bookstore/sj. The articles appearing in the Stata Journal may be copied or reproduced as printed copies. and Canada Elsewhere 1-year subscription $ 79 1-year subscription $115 2-year subscription $155 2-year subscription $225 3-year subscription $225 3-year subscription $329 3-year subscription (electronic only) $210 3-year subscription (electronic only) $210 1-year student subscription $ 48 1-year student subscription $ 79 1-year university library subscription $ 99 1-year university library subscription $135 2-year university library subscription $195 2-year university library subscription $265 3-year university library subscription $289 3-year university library subscription $395 1-year institutional subscription $225 1-year institutional subscription $259 2-year institutional subscription $445 2-year institutional subscription $510 3-year institutional subscription $650 3-year institutional subscription $750 Back issues of the Stata Journal may be ordered online at http://www. in whole or in part. in whole or in part. . Written permission must be obtained from StataCorp if you wish to make electronic copies of the insertions. or emailed to sj@stata. on publicly accessible websites. College Station. Users of any of the software.html The Stata Journal is published quarterly by the Stata Press. Stata. This precludes placing electronic copies of the Stata Journal. datasets. or online at http://www. The Stata Journal. 4905 Lakeway Drive.S.stata-journal. and help files) are copyright  c by StataCorp LP. TX 77845. .Subscriptions are available from StataCorp. or consequential damages such as loss of profits. in whole or in part. Texas. and NetCourse are registered trademarks of StataCorp LP. or other materials published in the Stata Journal or the supporting files understand that such use is made without warranty of any kind. fax 979-696-4601.stata. as long as any copy or reproduction includes attribution to both (1) the author and (2) the Stata Journal.html Individual articles three or more years old may be accessed online without charge.html Subscription rates listed below include both a printed and an electronic copy unless otherwise mentioned. The purpose of the Stata Journal is to promote free communication among Stata users. More recent articles may be ordered online. and help files) may be copied or reproduced by any means whatsoever. by either the Stata Journal. telephone 979-696-4600 or 800-STATA-PC. The contents of the supporting files (programs. . USA.com/archives. Texas 77845. USA.

one would have to use the nlsur command and write a function evaluator program as described in [R] nlsur and Poi (2008). Section 2 outlines the models and elasticity computations. 433–446 Easy demand-system estimation with quaids Brian P. The command fits Deaton and Muellbauer’s (1980b. one would have to use the nlsur command and write a function evaluator program as de- scribed in [R] nlsur and Poi (2008. Number 3.  c 2012 StataCorp LP st0268 . many users had difficulty adapting the function evaluator program to fit their specific applications. Stata Journal 8: 554–556). Blundell. Demographic variables can also be included in the model. I introduce the command quaids. Section 4 provides an example. Questions arise regularly on the Statalist email discussion forum. and obtaining price and expenditure elasticities required even more programming. to fit an almost-ideal demand system (AIDS) in Stata. quaids allows you to fit either the standard AIDS model of Deaton and Muellbauer (1980b) or the quadratic AIDS model of Banks.com Abstract. In this article. TX bpoi@stata. adding demographic variables was difficult. The quaids command solves those shortcomings. Postestimation tools calculate expenditure and price elasticities. Previously. almost-ideal demand system 1 Introduction Demand-system estimation is a popular task in Stata. Keywords: st0268. Poi StataCorp LP College Station. However. Blundell. quaids. which obviates the need for any programming by the user. Section 3 describes the quaids command and associated postes- timation commands. Moreover. Postestimation commands allow you to compute expenditure elasticities as well as compensated and uncompensated price elasticities. Review of Economics and Statistics 79: 527–539) quadratic variant. The rest of this article is organized as follows. Section 5 concludes the article. to fit an almost-ideal demand system in Stata. and I frequently receive private requests for assistance from users. Previously. and Lewbel (1997). Demographic variables can be specified and are in- corporated using Ray’s (1983) method.The Stata Journal (2012) 12. and Lewbel’s (1997. pp. American Eco- nomic Review 70: 312–326) original almost-ideal demand-system model as well as Banks.

Banks. the k goods could represent broad categories like housing. for an in-depth anal- ysis of consumer behavior and demand-system analysis. m) = + λ(p) (1) b(p) where ln a(p) is the transcendental logarithm function  k 1  k k ln a(p) = α0 + αi ln pi + γij ln pi ln pk (2) i=1 2 i=1 j=1 In this function. and most others set α0 to be slightly less than the lowest value of ln m observed in the data. . it turns out to be rather difficult. could be chosen based on a two-stage budgeting process. and Green (1995. I describe AIDS models and show how demographic variables are incor- porated by the quaids command. the k goods could represent different categories of food. In prin- ciple. . clothing. Blundell. in practice. and the amount to be spent on food. . The quadratic AIDS model of Banks. The quaids command requires the user to specify a value for α0 .434 Demand systems 2 Almost-ideal demand systems In this section.1 Basics We consider a consumer’s demand for a set of k goods for which the consumer has budgeted m units of currency. 2. The presentation here is brief. and savings. k. m. pi is the price of good i for i = 1. Whinston. food. utilities. . chap. b(p) is the Cobb–Douglas price aggregator %k b(p) = pβi i i=1 and  k λ(p) = λi ln pi i=1 Lowercase Greek letters other than α0 represent parameters to be estimated. see the classic monographs by Deaton and Muellbauer (1980a) and Mas-Colell. Alternatively. For example. Blundell. Deaton and Muellbauer (1980b). and Lewbel (1997) is based on the indirect utility function !" #−1 $−1 ln m − ln a(p) ln V (p. 3). and Lewbel (1997). α0 could be estimated jointly with the other parameters. m could represent household income. .

Let qi denote the quantity of good i consumed by a household. . . However. 316) suggest replacing that price index with the approximation ln a(p) ≈ j wj ln pj . the quadratic term in each expenditure share equation drops out. .1 resulting in a set of equations that can be fit by linear estimation techniques. Deaton and Muellbauer (1980b. γij = 0. Let eR (p. . . We use z to represent a vector of s characteristics. Therefore. I am asked how to fit those so-called “linearly approximated” AIDS models in Stata. and define the expenditure share for good i as wi = pi qi /m. i = 1.B. k j=1 a(p) This set of expenditure share equations requires nonlinear estimation techniques because of the price index ln a(p). i = 1. . u) denote the expendi- ture function of a reference household. Poi 435 Adding up. Occasionally. 1. 2. k j=1 a(p) b(p) a(p) When λi = 0 for all i. λi = 0. and γij = γji i=1 i=1 j=1 i=1 The quaids command imposes these conditions automatically. given the advances in software in the last 30 years and Stata’s nlsur command.2 Demographics The quaids command incorporates demographics by using the scaling technique intro- duced by Ray (1983) and extended to the quadratic AIDS model by Poi (2002a). the current implemen- tation does not allow the user to fit unrestricted models and test whether these axioms of demand analysis hold. and we are left with Deaton and Muellbauer’s (1980b) original AIDS model. . In the simplest case. fitting nonlinear systems nowadays is not much more difficult than fitting linear systems. βi = 0. where a reference household might be one that contains just a single adult. homogeneity. This price index was first introduced by Sir Richard Stone. Consider the original AIDS model without the quadratic term:  k " # m wi = αi + γij ln pj + βi ln . . we obtain the expenditure share equation for good i:  k " # & " #'2 m λi m wi = αi + γij ln pj + βi ln + ln . z could be a scalar representing the number of people in a household. P. and Slutsky symmetry impose the requirements that  k  k  k  k αi = 1. Thus testing H0 : λi = 0 ∀ i allows us to choose easily between the original AIDS and the quadratic AIDS models. Applying Roy’s identity to (1). the quaids command currently uses the price index defined in (2) and does not offer the option of using alternative price indices. .

a household with two adults and two infants will consume different goods than one comprising four adults. . we are left with the AIDS model with demographics used by Ray (1983). z. Ray further decomposes the scaling function as m0 (p. but it has the distinct advantage of resulting in expenditure share equations that closely mimic their counterparts without demograph- ics. z. As in Poi (2002a). I became aware of an article by Blacklow. u) The function m0 (p. This is not the only way to incorporate demographics into the quadratic AIDS model us- ing Ray’s (1983) method. Nicholas. If we set λi = 0 for all i. z) = pj j j=1 k The adding-up condition requires that j=1 ηrj = 0 for r = 1. u) as ) * (k βj (k η j z j=1 pj j=1 pj −1 ln φ(p. z) m0 (z)a(p) where % k η z c(p. u) = k u − 1 j=1 λj ln pj This functional form may look a bit odd. . who discuss alternative ways of incorporating demographic variables by directly modifying the expenditure share equations.2 2. While writing this article. and Ray (2010) that used Ray’s (1983) method to incorporate household com- position variables in the quadratic AIDS model. not controlling for any changes in consumption patterns. z. a household with four members will have higher expenditures than one with a single member. u) = m0 (p. u) × eR (p. The expenditure share equations take the form  k " # & " #'2 m λi m wi = αi + γij ln pj + (βi + η i z) ln + ln j=1 m0 (z)a(p) b(p) c(p. Also see Pollak and Wales (1981). s. z. u) scales the expenditure function to account for the household characteristics. . u) The first term measures the increase in a household’s expenditures as a function of z. . η j represents the jth column of s × k parameter matrix η. z. z. .436 Demand systems Ray’s method uses for each household an expenditure function of the form e(p. z. quaids parame- terizes φ(p. u) = m0 (z) × φ(p. The second term controls for changes in relative prices and the actual goods consumed. Following Ray (1983). even ignoring that the composition of goods consumed may change. quaids parameterizes m0 (z) as m0 (z) = 1 + ρ z where ρ is a vector of parameters to be estimated.

1. The elasticity computations are also performed by Mata routines.4 Estimation We assume there is an additive zero-mean error term associated with each of the k ex- penditure share equations. z) m0 (z) a(p) Compensated price elasticities are obtained from the Slutsky equation: C ij = ij + μi wj . the estimator is invariant to which equation is dropped. obtaining forecasts. . The function evaluator program required by nlsur. z) m0 (z) a(p) + . All of these routines are stored in the quaids utils. The formulas for elasticities for the standard AIDS model and models without demographics are nested within the more general variants. z) m0 (z) a(p) l The expenditure (income) elasticity for good i is & " #' 1  2λi m μi = 1 + βi + η i z + ln (3) wi b(p) c(p. and calculating elasticities. Tedious but straightforward algebra shows that the uncompensated price elasticity of good i with respect to changes in the price of good j is  & " #' 1  2λi m ij = −δij + γij − βi + η i z + ln × wi b(p) c(p. To avoid a singular error-covariance matrix.B.3 Elasticities We present the formulas for the elasticities for the quadratic AIDS model with demo- graphic variables.mata file. . 2.ado. 3 The quaids command suite Accompanying this article is a complete suite of commands for fitting AIDS models. Poi 437 2. so there is no option to make quaids drop some equation other than the last. which accompanies this article. . We estimate the parameters by iterated feasible generalized nonlinear least-squares estimation via Stata’s nlsur command with the ifgnls option. P. is a wrapper command that calls a Mata routine to compute the predicted expenditure share equations. & " #'2 .  βj + η j z λi m αj + γjl ln pl − ln b(p) c(p. The iterated feasible generalized nonlinear least-squares estimator is equivalent to the multivariate normal maximum-likelihood estimator for this class of problems. named nlsur quaids. These programs require Stata 12. the quaids command automatically omits the last equation before calling nlsur.

newvark } if in . the quaids command handles that automatically. Option level(#) sets the confidence level for confidence intervals. vce(vcetype) controls the type of variance–covariance matrix calculated. specify k variable names. . . varlistprices . varnamelnexp . with or without the quadratic expenditure term and with or without demographic variables. . but results will be meaningless if the ordering is not preserved. varnameexp .438 Demand systems 3. The expenditure share variables should sum to 1 for each observation. Specify the value for α0 in option anot(). see [R] nlsur. To fit a system with k goods. in the lnprices() option.     quaids varlistexpshares if in . varlistdemo . This option works just as it does for nlsur. quaids exits with an error message if that is not true of the data. cluster clustvar (where clustvar is the name of a clustering variable). use the predict command to obtain predicted values of the expenditure shares. Specify optional demographic variables. vcetype may be gnr (the default). Specify k price variables. or jackknife. Specify one or the other but not both. Specify one or the other but not both. in option demographics(). in the option lnexpenditure(). robust. anot(#) {prices(varlistprices ) | lnprices(varlistlnprices )} {expenditure(varnameexp ) | lnexpenditure(varnamelnexp )}   demographics(varlistdemo ) noquadratic nolog vce(vcetype) level(#) varlistexpshares represents the variables containing the expenditure shares. Do not omit one of the goods to avoid a singular error-covariance matrix during estimation.. The expenditure variable should represent total expenditures on the goods that this demand system represents such that j pj qj = m for each observation in the dataset.2 Prediction After fitting an AIDS model. 3. varlistlnprices . Option noquadratic instructs quaids to omit the quadratic term. in the prices() option or specify k variables containing the natural logarithms of the prices of the k goods.       predict type {stub* | newvar1 . in the option expenditure() or specify the variable containing the natural logarithm of expenditure. quaids has no way to verify this.1 Estimation command The quaids command fits an AIDS model. The price variables must appear in the same order as the expenditure share variables. Specify the total expenditure variable. Option nolog suppresses the iteration log. bootstrap.

with this option. some users have had significant difficulty writing the requisite function evaluator program for use with nlsur. The current implementation does not compute standard errors for the elasticity estimates.. few of those users ask about obtaining elasticities. . . but remarkably. specify if e(sample) to restrict computations to only those observations used during estimation. . These commands allow you to compute the elasticities at the means of all the variables in the model or to compute the elasticities for each observation in the current dataset. where k is the number of goods in the demand system. First. However. the estat commands compute the statistics for all the observations in the dataset unless you use the if or in modifiers to restrict the sample. If the user specifies. To compute the expenditure elasticities for individual observations in the dataset. Alterna- tively.3 Elasticities One is often more interested in the expenditure and price elasticities rather than in the parameters of the expenditure share equations per se. You can compute elasticities for various subsets of the data by creating an artificial dataset containing the appropriate variable means. There are at least two reasons. you may specify either a vari- able stub or k new variable names. say. you may specify atmeans to have the commands first compute the means of the price. The example in the next section illustrates how to compute elasticities for “average” rural and urban households. In both cases. the predictions are computed for all observations in the dataset. and demographic variables. The quaids command includes three postestimation utilities for computing expen- diture elasticities as well as compensated and uncompensated price elasticities.B. newvark } if in Similarly to the predict command discussed above. The jth new variable will contain the expenditure elasticity for the jth good. I often receive email questions asking for help fitting an AIDS model. All three of the estat commands accompanying this article will compute elasticities for each observation in the dataset and place the results in new variables. . . by default. what*. P. expenditure. Poi 439 Specify stub immediately followed by an asterisk (*). . By default. then the new variables created will be named what1. . so writing a pro- gram to compute the elasticities or using the nlcom command to do so may be out of reach. the elasticities are returned as a vector or matrix. Second. whatk. I suspect that many Stata users attempting to fit demand systems give up before computing the elastici- ties.. 3. or specify k new variable names. and then compute the elasticities at the means of those variables. you type       estat expenditure type {stub* | newvar1 .

1 . v1. . atmeans . . To compute the uncompensated price elasticities at the means of all the variables and have the results returned in a k × k matrix. type       estat uncompensated type {stub* | newvar1 . . . . estat expenditure computes the means of all the price. newvark2 } if in Specify a stub or specify k2 new variables. . Compensated price elasticities are obtained similarly to uncompensated price elas- ticities. type     estat uncompensated if in . type     estat compensated if in . ..j represents the elasticity of good i with respect to changes in the price of good j. . where vi. .k . . .1 . . The entry in row i..1 . we strongly recom- mend specifying a new variable stub rather than specifying k 2 new variables. To obtain observation-specific compensated price elasticities.440 Demand systems To compute the expenditure elasticities at the means of all the variables and have the result returned in a 1 × k vector. . . expenditure. To compute the uncompensated price elasticities for individual observations in the dataset. .k . . . estat uncompensated computes a k × k matrix. To avoid confusion. atmeans With this syntax. Variables are created in the order v1. v2. column j contains the elasticity of good i with respect to the price of good j.k . . estat uncompensated adds variable labels to the new variables to aid in interpretation. vk. type     estat expenditure if in . . . and demographic variables of your model and computes the expenditure elasticities for the k goods at those means. . . type       estat compensated type {stub* | newvar1 . v2. newvark2 } if in To compute the compensated price elasticities at the means of all the variables. atmeans With this syntax. vk.

the vector of expenditure elasticities. The i. atmeans saves r(uncompelas). The i. estat compensated. Poi 441 3. estat uncompensated. atmeans saves r(expelas). Err. j entry is the elasticity of good i with regard to price j. . atmeans saves r(compelas). j entry is the elasticity of good i with regard to price j.4 Saved results quaids saves the following in e(): Scalars e(N) number of observations e(ll) log likelihood e(N clust) number of clusters e(ndemos) number of demographics e(anot) value of α0 e(ngoods) number of goods Macros e(cmd) quaids e(clustvar) name of cluster variable e(vce) vcetype specified in vce() e(vcetype) title used in label Std.B. e(properties) b V e(estat cmd) program used to implement estat e(predict) program used to implement predict e(demographics) demographic variables included e(lhs) expenditure share variables e(expenditure) expenditure variable e(lnexpenditure) log-expenditure variable e(prices) price variables e(lnprices) log-price variables e(quadratic) noquadratic Matrices e(b) coefficient vector e(V) variance–covariance matrix of the estimators e(alpha) estimated α vector e(beta) estimated β vector e(gamma) estimated γ matrix e(lambda) estimated λ vector (if applicable) e(eta) estimated η matrix (if applicable) e(rho) estimated ρ vector (if applicable) Functions e(sample) marks estimation sample estat expenditure. the matrix of compensated price elasticities. P. the matrix of uncompensated price elasticities.

We then fit a quadratic AIDS model using α0 = 10. anot(10) prices(p1-p4) expenditure(expfd) > demographics(nkids rural) nolog (obs = 4048) Calculating NLS estimates. We first create a random integer representing the number of children in each household and a random binary variable representing rural versus urban households so that we can demonstrate a model that includes demographics. FGNLS iteration 4. . generate nkids = int(runiform()*4) . webuse food .. quaids w1-w4. . and [R] nlsur. we use the nolog option to suppress the iteration log.7) .. set seed 1 .. generate rural = (runiform() > 0.. Poi (2008)... FGNLS iteration 3.. Calculating FGNLS estimates.. FGNLS iteration 2..442 Demand systems 4 Example Here we illustrate the quaids command using the same dataset used in Poi (2002b). To save space..

0000165 .0133462 -4.0419878 0. and the maximized value of the log-likelihood function assuming multivariate normal errors.6055631 The header of the output indicates the type of model fit.0082844 gamma_4_4 .026 -.1318313 .001576 rho rho_nkids -.1262665 .0005117 lambda_4 -.343 -.70 0.0400439 .0746098 .0777736 lambda lambda_1 .070847 2.0075466 1.23 0.015612 -2.000 -.B.14 0.0385279 .23 0.453 -.73 0.0098439 . the value of α0 used.052 -.0091552 .2800049 .0008446 eta_nkids_2 -.94 0.004 -. Poi 443 Quadratic AIDS model Number of obs = 4048 Number of demographics = 2 Alpha_0 = 10 Log-likelihood = 13098.889 -.08 0.0869016 -.0132605 .0005239 .0465848 .0046248 lambda_3 -.2068199 .0002466 0.2314054 .93 0.0148814 -.3456775 beta beta_1 .0022102 eta_rural_3 .91 0. The table of estimated pa- rameters is divided into groups representing each vector or matrix that appears in the .000 .0099638 .12 0.004 .0305337 -4.053 -.0293852 gamma_4_2 .000 .02 0.21 0.0607434 .000 .0002339 . the number of observa- tions and demographic variables.32 0.88 0.0179386 .0155448 .0684371 .1779231 gamma_3_2 .2708105 beta_2 -.84 0.060 -.0097531 .0008155 0.1145233 -.179 -.0029482 6.136 -.49 0.0347438 .0406422 rho_rural .1328957 .75 0.000 .0007044 -1.0780093 beta_3 -.046504 6.000331 eta_rural_2 .0002494 .0118494 0. z P>|z| [95% Conf.005 -.020 -.1866283 -.55 0.0003542 -1.0696028 13.0007173 eta_rural_1 -.71 0.2106693 -.711 -.0667499 .0002252 .83 0.94 0.0263559 4.0002186 eta_nkids_3 .37 0.0001179 0.33 0.0060638 -.000 -.0707108 -1.09 0.1427523 .0010496 .69 0.0145941 .0237169 lambda_2 -.34 0.0294805 7.0909794 gamma_3_1 -.922 -.000 .000316 0.966 Coef.0004354 .0546416 gamma_4_3 -.0679623 .1888587 .1508244 .0002797 0.1552492 . Err.95 0.0026165 -3.0009866 .2230204 -.0653428 -.000 .0992743 .0048978 .000197 .0056949 alpha_3 .0007489 .400 -.0011699 .78 0.0345853 gamma_4_1 -.0014164 -2.0000483 eta eta_nkids_1 . Std.0044489 -0.79 0.2714863 .0025236 -1.931 -.0096251 6.2130298 .0032877 .0465259 -2.08 0.0121603 .910531 .0041107 11.0331881 gamma_3_3 .0041449 beta_4 -.0589087 .0002147 .0004135 .0277094 -4.1909003 1.92 0.022351 gamma_2_2 .0006118 .091 -. Interval] alpha alpha_1 .0005724 eta_rural_4 . P.0978394 alpha_4 .000 .0235138 -2.0459672 .0003941 .0002476 eta_nkids_4 .000 -.027198 -1.476 -.04695 alpha_2 -.225 -.0024301 .000 -.7741121 1.3711511 gamma_2_1 -.486 -.0004756 .0005931 0.0000242 .0073399 gamma gamma_1_1 .10 0.1323188 .

Here we test the null hypothesis that the dummy variable rural plays no significant role in determining expenditure patterns. then the fourth must be 0 as well. Commands like test and testnl can be used to perform Wald tests on the parame- ters just like any other estimation command. We are often more interested in the expenditure and price elasticities rather than in the estimated coefficients per se. accumulate ( 1) [eta]eta_rural_1 = 0 ( 2) [eta]eta_rural_2 = 0 ( 3) [eta]eta_rural_3 = 0 ( 4) [eta]eta_rural_4 = 0 ( 5) [rho]rho_rural = 0 Constraint 4 dropped chi2( 4) = 3. notest accumulate We would have obtained the same test statistic either way. test [eta]_b[eta_rural_1]. Given that our rural variable was randomly generated. we are not surprised that the test statistic does not allow us to reject the null hypothesis. If that null hypothesis is true. then all elements of the row of the η matrix corresponding to rural must be jointly 0. knowing that. we could have omitted the line . along with the corresponding element of the ρ vector.4909 The output from test indicates that Constraint 4 dropped.444 Demand systems demand system. Recall that the rows of η are constrained to sum to 0. Here we compute the expenditure elasticities for each household in the dataset and then summarize them: . testing whether all four elements are equal to 0 is equivalent to testing whether the first three are equal to 0. test [eta]_b[eta_rural_3]. notest ( 1) [eta]eta_rural_1 = 0 . In fact. test [eta]_b[eta_rural_2]. . test [eta] b[eta rural 4]. Inspection reveals that the estimated parameters satisfy the adding-up and homogeneity conditions. notest accumulate ( 1) [eta]eta_rural_1 = 0 ( 2) [eta]eta_rural_2 = 0 ( 3) [eta]eta_rural_3 = 0 ( 4) [eta]eta_rural_4 = 0 . If the first three elements of the row corresponding to rural are each equal to 0. test [rho]_b[rho_rural]. notest accumulate ( 1) [eta]eta_rural_1 = 0 ( 2) [eta]eta_rural_2 = 0 . test [eta]_b[eta_rural_4]. Therefore. notest accumulate ( 1) [eta]eta_rural_1 = 0 ( 2) [eta]eta_rural_2 = 0 ( 3) [eta]eta_rural_3 = 0 .42 Prob > chi2 = 0.

74128023 .0024687 1.73724268 .13132521 -.03848514 -.9296512 Recall that (3) includes wi in the denominator of a fraction.1021857 -. column j of each elasticity matrix represents the percentage change in the quantity of good i consumed for a 1% change in the price of good j.4] c1 c2 c3 c4 r1 -1.2458694 .04191575 .25505899 r2 . P.25314115 r2 .42106 . Next we compute the uncompensated price elasticities for “representative” rural and urban households.04011097 .55763258 . and we use an if condition to restrict computations to the relevant subsample. To do that.061976 -31. atmeans . if wi is close to 0. When computing household-level elasticities.36542124 -.07559882 -.05041919 r4 . Moreover.12743289 r3 .05029575 r4 .74813 .06701876 -. matrix list upurban upurban[4. a 1% increase in the price of good A raises consumption of good B by 0.9005266 -22.10694767 -. matrix list uprural uprural[4. .32700506 -.2651808 -.8235479 -45. you should therefore be cognizant of extreme values for some households and perhaps use summary statistics such as medians that are not influenced by outliers.12540763 r3 . Min Max e_1 4039 1. Among rural consumers.33%. then the expenditure elasticity will be very large in magnitude.B. summarize e_1-e_4 Variable Obs Mean Std. Dev.0511128 -.00975406 -.7976551 e_3 3996 .55976996 . matrix uprural = r(uncompelas) .3038599 -.4] c1 c2 c3 c4 r1 -1. Thus if a household does not consume a particular item (wi = 0). matrix upurban = r(uncompelas) . where we set all variables other than rural equal to their group-level means.08810754 -. Poi 445 .01060621 -. the expenditure elasticity will be infinite (a missing value in Stata parlance). we use the atmeans option of estat uncompensated.75058651 . estat uncompensated if rural. estat uncompensated if !rural. . atmeans .56926 .1296122 -.74324303 The entry in row i.399172 1.06235336 -.261789 59.0934749 -.966449 1.43863 e_2 4029 -. That explains why the number of nonmissing observations for each of our four expenditure elasticities is less than the estimation sample size.631619 .04814826 -.9050692 e_4 4047 . estat expenditure e* .

2002a. and R. Measuring the costs of children: An alternative approach. Wales.. 2008. Even if users were successful in fitting an AIDS model. 1981. ———. American Economic Review 70: 312– 326. Stata Journal 2: 403–410. D. Demographic variables in demand analysis. many probably struggled with computing elasticities. An almost ideal demand system. M. Poi. A. this proved a challenge for beginners. Widely dis- tributed example programs did not allow for demographic variables either. ———. About the author Brian Poi is a senior economist at StataCorp LP. ———. From the help desk: Demand system estimation.. and A. 6 References Banks. Nicholas. Stata Journal 8: 554–556. Journal of Public Economics 22: 89–102. to fit an AIDS model in Stata. In Three Essays in Applied Econometrics. Demand-system estimation: Update. Cam- bridge: Cambridge University Press. Econometrica 49: 1533–1551. and T. a user would have to write his or her own program to be used with nlsur. Ray. Mas-Colell.. Lewbel. Dairy policy and consumer welfare. J. Muellbauer. Demographic demand systems with ap- plication to equivalence scales estimation and inequality analysis: The Australian evidence. Review of Economics and Statistics 79: 527–539. Australian Economic Papers 49: 161–179. Doctoral thesis. Ray. 1983. Department of Economics. Blacklow. and J. A. Chapter II. and J. J. Economics and Consumer Behavior. P. P. 2010. 2002b. He is indebted to Kompal Sinha and Helder Zavale for valuable feedback on an earlier draft of this article and the quaids command. 1980a. New York: Oxford University Press.446 Demand systems 5 Conclusion Previously. R. A. 1997. University of Michigan. Deaton. Whinston. Quadratic Engel curves and consumer demand. 1995. and it allows one to include demographic variables. Green. postestimation commands after quaids make those tasks easy. Blundell. . 1980b. Pollak. R. R... S. The new quaids command removes all programming-related barriers to fitting these models in Stata. A. Microeconomic Theory. B. R.