Announcement

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

  • Tabulating decile cutoff values

    I have a variable mpce for which i need to find out the deciles,and the cutoff values for those deciles. While I could find the deciles, and could list the decile cutoff values, I cant find a simple way to get those cutoff values in a tabular form. The tabstat option gives me percentile values but not the deciles.

    I used xtile decile = mpce, nq(10) to get the deciles

    pctile dec = mpce, nq(10) gives me the 9 cutoffs as a variable dec

    But what I am asking is that is there any way to tabulate those 9 values

    I need to export those that table into a latex code so a table would be nice. If not, are there any ways (other than manually creating a table) by which I could make a table of the decile cutoff values ?

  • #2
    If you have Stata 18, you can build a custom table of deciles using dtable. Then you can customize the table as you like.

    Here is a simple example using the auto data.
    Code:
    cls
    clear all
    
    sysuse auto
    
    * list of statistics of interest
    local deciles p10 p20 p30 p40 p50 p60 p70 p80 p90
    
    * compute statistics of interest, with custom format
    dtable mpg turn trunk, ///
        continuous(, statistics(`deciles')) ///
        nformat(%9.1f `deciles')
    
    * default labels are long, so just show their names
    collect style header result[`deciles'] , level(value)
    * reset result auto levels to statistics of interest, -dtable- set a
    * composite result by default
    collect style autolevels result `deciles', clear
    * arrange table
    collect layout (var) (result)
    
    * export to a LaTeX file you can call with -pdflatex-
    collect export deciles.tex, replace
    Here is the resulting table.
    Code:
    ------------------------------------------------------------------
                           p10  p20  p30  p40  p50  p60  p70  p80  p90
    ------------------------------------------------------------------
    Mileage (mpg)         14.0 17.0 18.0 19.0 20.0 22.0 24.0 25.0 29.0
    Turn circle (ft.)     34.0 35.0 36.0 38.0 40.0 42.0 43.0 43.0 45.0
    Trunk space (cu. ft.)  8.0 10.0 11.0 12.0 14.0 16.0 16.0 17.0 20.0
    ------------------------------------------------------------------
    Here is a screenshot of the table from Preview on my Mac, after creating a PDF from deciles.tex via pdflatex.

    Click image for larger version

Name:	Screenshot 2024-04-14 at 12.47.47 PM.png
Views:	1
Size:	61.4 KB
ID:	1749907

    Comment


    • #3
      If you have Stata 17, here is the same example built using table.
      Code:
      clear all
      
      sysuse auto
      
      * list of statistics of interest
      local deciles p10 p20 p30 p40 p50 p60 p70 p80 p90
      
      * compute statistics of interest, with custom format
      local vlist mpg turn trunk
      table (var) (result), ///
          statistic(p10 `vlist') ///
          statistic(p20 `vlist') ///
          statistic(p30 `vlist') ///
          statistic(p40 `vlist') ///
          statistic(p50 `vlist') ///
          statistic(p60 `vlist') ///
          statistic(p70 `vlist') ///
          statistic(p80 `vlist') ///
          statistic(p90 `vlist') ///
          nformat(%9.1f)
      
      * default labels are long, so just show their names
      collect style header result[`deciles'] , level(value)
      * show effect of label change
      collect preview
      
      * export to a LaTeX file you can call with -pdflatex-
      collect export deciles.tex, replace

      Comment

      Working...
      X