DOI: 10.7910/dvn/utnjah
title: Consumer Expenditure Survey (CE)

description: &lt;h3 class="post-title entry-title" itemprop="name"&gt; analyze the consumer expenditure survey (ce) with r &lt;/h3&gt; the consumer expenditure survey (ce) is the primo data source to understand how americans spend money. participating households keep a running diary about every little purchase over the year. those diaries are then summed up into precise expenditure categories. how else are you gonna know that the average american household spent $34 (&lt;span class="st"&gt;±&lt;/span&gt;2) on bacon, $826 (&lt;span
class="st"&gt;±17) &lt;/span&gt;on cellular phones, and $13 (&lt;span class="st"&gt;±2) &lt;/span&gt;on digital e-readers in 2011? an integral component of &lt;a href="http://www.bls.gov/cpi/cpifaq.htm#Question_6"&gt;the market basket calculation&lt;/a&gt; in &lt;a href="http://www.bls.gov/cpi/"&gt;the consumer price index&lt;/a&gt;, this survey recently became available as public-use microdata and they're &lt;a href="http://www.bls.gov/cex/pumdhome.htm#online"&gt;slowly releasing historical files back to 1996&lt;/a&gt;. hooray!&lt;br /&gt; &lt;br /&gt; for a t
aste of what's possible with ce data, look at &lt;a href="http://www.bls.gov/cex/#tables"&gt;the quick tables&lt;/a&gt; listed on their main page - these tables contain approximately a bazillion different expenditure categories broken down by demographic groups. guess what? i just learned that americans living in households with $5,000 to $9,999 of annual income spent an average of $283 (&lt;span class="st"&gt;±90&lt;/span&gt;) on pets, toys, hobbies, and playground equipment (&lt;a href="http://www.bls.gov/cex/2011/Sta
ndard/income.pdf"&gt;pdf page 3&lt;/a&gt;). you can often get close to your statistic of interest from these web tables. but say you wanted to look at domestic pet expenditure among only households with children between 12 and 17 years old. another one of the thirteen web tables - &lt;a href="http://www.bls.gov/cex/2011/Standard/cucomp.pdf"&gt;the consumer unit composition table&lt;/a&gt; - shows a few different breakouts of households with kids, but none matching that exact population of interest. the &lt;a href="
http://www.bls.gov/"&gt;bureau of labor statistics (bls)&lt;/a&gt; (the survey's designers) and the &lt;a href="http://census.gov/"&gt;census bureau&lt;/a&gt; (the survey's administrators) have provided plenty of the major statistics and breakouts for you, but they're not psychic. if you want to comb through this data for specific expenditure categories broken out by a you-defined segment of the united states' population, then let a little r into your life. fun starts now.&lt;br /&gt; &lt;br /&gt; fair warning: only analyze t
he consumer expenditure survey if you are nerd to the core. the microdata ship with two different survey types (interview and diary), each containing five or six quarterly table formats that need to be
&lt;a href="http://stat.ethz.ch/R-manual/R-patched/library/base/html/cbind.html"&gt;stacked&lt;/a&gt;, &lt;a href="http://rss.acs.unt.edu/Rdoc/library/base/html/merge.html"&gt;merged&lt;/a&gt;, and manipulated prior to a methodologically-correct analysis. the scripts in this repository contain examples to prepare 'em all, just be advised that magnificent data like this will never be no-assembly-required. the folks at bls have posted &lt;a href="http://www.bls.gov/cex/pumdhome.htm#about"&gt;an excellent summary of what's av
ailable&lt;/a&gt; - read it before anything else. after that, read the &lt;a href="http://www.bls.gov/cex/pumd_novice_guide.pdf"&gt;getting started guide&lt;/a&gt;. don't skim.&lt;br /&gt; &lt;br /&gt; a few of the descriptions below refer to sas programs provided by the bureau of labor statistics. you'll find these in the C:\My Directory\CES\2011\docs directory after you run the download program. this new github repository contains three scripts:&lt;br /&gt; &lt;br /&gt; &lt;b&gt;2010-2011 - download all microdata.R&lt;/b&gt;&lt;br /&gt; &lt;ul&gt; &lt;li&gt;lo
op through every year and download every file hosted on the bls's ce ftp site
&lt;/li&gt; &lt;li&gt;import each of the comma-separated value files into r with &lt;a href="http://stat.ethz.ch/R-manual/R-patched/library/utils/html/read.table.html"&gt;read.csv&lt;/a&gt;&lt;/li&gt; &lt;li&gt;depending on user-settings, save each table as an&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;&lt;a href="http://stat.ethz.ch/R-manual/R-patched/library/base/html/save.html"&gt;r data file&lt;/a&gt;&lt;span class="Apple-converted-space"&gt; &lt;/span&gt;(.rda) or &lt;a href="http://stat.ethz.ch/R-manual/R-devel/library/foreign/html/read.dta.html"&gt;stat
a-readable file&lt;/a&gt; (.dta) &lt;/li&gt; &lt;/ul&gt; &lt;br /&gt; &lt;b&gt;2011 fmly intrvw - analysis examples.R&lt;/b&gt;&lt;b&gt;&lt;/b&gt;&lt;br /&gt; &lt;ul&gt; &lt;li&gt;load the &lt;a href="http://stat.ethz.ch/R-manual/R-devel/library/base/html/load.html"&gt;r data files&lt;/a&gt; (.rda) necessary to create the 'fmly' table shown in the ce macros program documentation.doc file&lt;/li&gt; &lt;li&gt;construct that 'fmly' table, using five quarters of interviews (q1 2011 thru q1 2012)&lt;/li&gt; &lt;li&gt;initiate a &lt;a href="http://faculty.washington.edu/tlumley/survey/html/svrepdesign.h
tml"&gt;replicate-weighted survey design&lt;/a&gt; object&lt;a href="ftp://ftp.cdc.gov/pub/health_statistics/nchs/dataset_documentation/nhis/2011/srvydesc.pdf"&gt;&lt;/a&gt;&lt;/li&gt; &lt;li&gt;perform some lovely li'l analysis examples&lt;/li&gt; &lt;li&gt;replicate the &lt;i&gt;%mean_variance()&lt;/i&gt; macro found in "ce macros.sas" and provide some examples of calculating descriptive statistics using &lt;i&gt;unimputed &lt;/i&gt;variables&lt;/li&gt; &lt;li&gt;replicate the &lt;i&gt;%compare_groups()&lt;/i&gt; macro found in "ce macros.sas" and provide some examples of performing t
-tests using &lt;i&gt;unimputed &lt;/i&gt;variables&lt;/li&gt; &lt;li&gt;create an &lt;a href="http://cran.r-project.org/web/packages/RSQLite/RSQLite.pdf"&gt;rsqlite database&lt;/a&gt; (to minimize ram usage) containing the five imputed variable files, after identifying which variables were imputed based on &lt;a href="http://www.bls.gov/cex/csxguide.pdf"&gt;pdf page 3&lt;/a&gt; of the user's guide to income imputation&lt;/li&gt; &lt;li&gt;initiate a replicate-weighted, &lt;a href="http://faculty.washington.edu/tlumley/survey/svy-dbi.html"&gt;database-backed&lt;/
a&gt;, &lt;a href="http://faculty.washington.edu/tlumley/survey/svymi.html"&gt;multiply-imputed&lt;/a&gt; survey design object&lt;/li&gt; &lt;li&gt;perform a few additional analyses that highlight &lt;a href="http://rss.acs.unt.edu/Rdoc/library/mitools/html/MIcombine.html"&gt;the modified syntax required&lt;/a&gt; for multiply-imputed survey designs&lt;/li&gt; &lt;li&gt;replicate the &lt;i&gt;%mean_variance()&lt;/i&gt; macro found in "ce macros.sas" and provide some examples of calculating descriptive statistics using &lt;i&gt;imputed &lt;/i&gt;variables&lt;/li&gt; &lt;li&gt;repl
icate the &lt;i&gt;%compare_groups()&lt;/i&gt; macro found in "ce macros.sas" and provide some examples of performing t-tests using &lt;i&gt;imputed &lt;/i&gt;variables&lt;/li&gt; &lt;li&gt;replicate the &lt;i&gt;%proc_reg()&lt;/i&gt; and &lt;i&gt;%proc_logistic()&lt;/i&gt; macros found in "ce macros.sas" and provide some examples of regressions and logistic regressions using both &lt;i&gt;unimputed&lt;/i&gt; and &lt;i&gt;imputed &lt;/i&gt;variables&lt;/li&gt; &lt;/ul&gt; &lt;br /&gt; &lt;b&gt;replicate integrated mean and se.R&lt;/b&gt;&lt;br /&gt; &lt;ul&gt; &lt;li&gt;match each step in the bls-provided sas program "integr
ated mean and se.sas" but with r instead of sas&lt;/li&gt; &lt;li&gt;create an &lt;a href="http://cran.r-project.org/web/packages/RSQLite/RSQLite.pdf"&gt;rsqlite database&lt;/a&gt; when the expenditure table gets too large for older computers to handle in ram &lt;/li&gt; &lt;li&gt;export a table "2011 integrated mean and se.csv" that exactly matches the contents of the sas-produced "2011 integrated mean and se.lst" text file&lt;/li&gt; &lt;/ul&gt; &lt;br /&gt; &lt;br /&gt; &lt;a href="https://github.com/ajdamico/usgsd/tree/master/Consumer%20Expenditure%20Su
rvey"&gt;click here to view these three scripts&lt;/a&gt;&lt;br /&gt; &lt;br /&gt; &lt;br /&gt; &lt;br /&gt; for more detail about the consumer expenditure survey (ce), visit:&lt;br /&gt; &lt;ul&gt; &lt;li&gt;the bureau of labor statistics' &lt;a href="http://www.bls.gov/cex/"&gt;consumer expenditure survey homepage&lt;/a&gt;&lt;/li&gt; &lt;li&gt;&lt;a href="http://www.bls.gov/cex/csxsurveyforms.htm"&gt;the survey questionnaire&lt;/a&gt;&lt;/li&gt; &lt;li&gt;the national bureau of economic research's (old) &lt;a href="http://www.nber.org/data/ces_cbo.html"&gt;family-level ce extract page&lt;/a&gt;&lt;/li&gt; &lt;
/ul&gt; &lt;br /&gt; notes:&lt;br /&gt; &lt;br /&gt; throughout this post, i've used the terms consumer unit and household interchangeably. &lt;a href="http://www.bls.gov/cex/faq.htm#q3"&gt;consumer unit&lt;/a&gt; is a precise definition, but household is a reasonable proxy that will make more sense to your audience. the consumer expenditure survey is a consumer unit-level survey, meaning all weights and results generalize to the average (non-institutional) american consumer unit. since the unit of analysis is one consumer u
nit rather than one person, it's trickier to talk about your results. instead of saying, "in 2011, the average american spent $x on y," you'll have to say, "in 2011, the average american household spent $y on z." if your boss frowns at you, blame it on me.
&lt;br /&gt; &lt;br /&gt; if you're hard-pressed to talk about expenses at the individual-level, you could copy what the social security administration did on &lt;a href="http://www.ssa.gov/policy/docs/chartbooks/expenditures_aged/exp_aged.pdf"&gt;pdf page 11 of this report&lt;/a&gt; and compute per capita expenditures, but i don't recommend it. if you desperately need to open up that can of worms, run your analytic plan by &lt;a href="http://www.bls.gov/cex/csxcont.htm"&gt;the folks at bls&lt;/a&gt; and get their blessing. othe
rwise, stick with household. small price for wonderful data.&lt;br /&gt; &lt;br /&gt; confidential to sas, spss, stata, and sudaan users: why are you still using medieval inventions? you don't see airplane pilots navigating by the stars. time to transition to r. :D