Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • What is the best way to tabulate means using sampling weights?

    I have often wanted to use sampling weights to generate tables of mean values for a variable. The tabulate command does not let one use sampling weights (pweight), and my solution which follows looks long-winded. Is there a better method? I use the mean command iteratively, and then copy the values by hand onto the table I want.

    Code:
    local agedesc: value label agecat
    local gendesc: value label male
    local urbandesc: value label urban
    foreach a in 0 1 2 3 4 5 {
     local label: label `agedesc' `a'
     display " "
     display " "
     display " ---------------------------------------------------------- "
     display "                     Age category: `label' "
     display " ---------------------------------------------------------- "
     foreach g in 0 1 {
      local label: label `gendesc' `g'
      display " "
      display " ---------------- Gender: `label' ----------------"
      foreach u in 0 1 {
       local label: label `urbandesc' `u'
       display " "
       display "`label'"
       mean pscomp if agecat==`a' & male==`g' & urban==`u' [pweight=swgt]
       
       }
      }
     }

  • #2
    Do you want both, the means and the standard errors in your table or only the means? In the latter case you can use aweights instead of pweights, so something like

    Code:
    . sysuse auto
    .tabulate for rep78 [aw=weight],  sum(mpg) nost nofreq noobs
    might be used. A solution with collapse also comes to my mind. If you want the standard errors as well you may want to -mean-'s -over()- option:

    Code:
     . mean mpg [pw=weight], over(for rep78)
    It seems to me that you also asks for how to create a publication ready table of the results of -mean- with a varlist in the over-option. If this were the case I recommend to start with the command above and then go on working with the saved results of that command.

    Uli

    Comment


    • #3
      You might also want to check out Ian Watson's tabout, available from SSC.

      Code:
      . ssc describe tabout
      
      -------------------------------------------------------------------------------
      package tabout from http://fmwww.bc.edu/repec/bocode/t
      -------------------------------------------------------------------------------
      
      TITLE
            'TABOUT': module to export publication quality cross-tabulations
      
      DESCRIPTION/AUTHOR(S)
            
             tabout is a table building program for oneway and twoway
            tables of frequencies and percentages, and for summary tables. It
            produces publication quality tables for export to a text file.
            These tables can then be used with spreadsheets, word processors,
            web browsers or compilers like LaTeX. The tables produced by
            tabout allow multiple panels so that a number of variables can be
            included in the one table. tabout also provides standard errors
            and confidence intervals, as well as a range of table statistics
            (chi2 etc). The output from tabout matches Stata's tabulate, most
            of tabstat and some of table.
            
            KW: tables
            KW: latex
            KW: html
            KW: delimited text
            
            Requires: Stata version 9.2
            
            Distribution-Date: 20150112
            
            Author: Ian Watson , Macquarie University, Australia
            Support: email [email protected]
            
      
      INSTALLATION FILES                               (type net install tabout)
            tabout.ado
            tabstatout.ado
            tabout.hlp
            ../f/figout.ado
            ../f/figout.hlp
      
      ANCILLARY FILES                                  (type net get tabout)
            tabout_tutorial.pdf
            ../e/examples_tab.do
            ../e/examples_tex.do
            ../b/bot.tex
            top.tex
      -------------------------------------------------------------------------------
      (type ssc install tabout to install)
      David Radwin
      Senior Researcher, California Competes
      californiacompetes.org
      Pronouns: He/Him

      Comment

      Working...
      X