Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Stata is two-timing me... (Possible -tabulate- & -table- time format bug)


From   "David Elliott" <dcelliott@gmail.com>
To   statalist@hsphsun2.harvard.edu
Subject   st: Stata is two-timing me... (Possible -tabulate- & -table- time format bug)
Date   Tue, 25 Sep 2007 14:54:31 -0300

I recently had this puzzle with time formats and tabulations.
I was generating a month variable and initially got the expected
results.  However, when I changed to a display format that was wider,
both tabulate and table applied inappropriate time formats to the row
headings.

. gen mdos=mofd(dos)

. levelsof mdos
555 556 557 558 559 560 561 562 563 564 565 566

. format mdos %tmCY!mn

. list dos mdos in 1/3

     +---------------------+
     |       dos      mdos |
     |---------------------|
  1. | 09apr2006   2006m4  |
  2. | 10apr2006   2006m4  |
  3. | 11apr2006   2006m4  |
     +---------------------+

. tab mdos

       mdos |      Freq.     Percent        Cum.
------------+-----------------------------------
     2006m4 |        170        7.54        7.54
     2006m5 |        189        8.38       15.92
     2006m6 |        221        9.80       25.72
...

. format mdos %tmM_CY

. list mdos in 1/3

     +------------+
     |       mdos |
     |------------|
  1. | April 2006 |
  2. | April 2006 |
  3. | April 2006 |
     +------------+

. tab mdos

       mdos |      Freq.     Percent        Cum.
------------+-----------------------------------
  09jul1961 |        170        7.54        7.54
  10jul1961 |        189        8.38       15.92
  11jul1961 |        221        9.80       25.72
...

. table mdos, stubwidth(20)

---------------------------------
                mdos |      Freq.
---------------------+-----------
           09jul1961 |        170
           10jul1961 |        189
           11jul1961 |        221
...

Some experimentation with the width of the display format demonstrates
that at width 9 the display works properly but with a width of >9 it
reverts to a %d format rather than a %tm format.  I've shown this with
adding some padded spaces to the display format.

* 9 spaces
. format mdos %tmCY__l

. tab mdos

       mdos |      Freq.     Percent        Cum.
------------+-----------------------------------
  2006  apr |        170        7.54        7.54
  2006  may |        189        8.38       15.92
  2006  jun |        221        9.80       25.72
...

* 10 spaces
. format mdos %tmCY___l

. tab mdos

       mdos |      Freq.     Percent        Cum.
------------+-----------------------------------
  09jul1961 |        170        7.54        7.54
  10jul1961 |        189        8.38       15.92
  11jul1961 |        221        9.80       25.72
...

-tabulate- is a built in command, but -table- is implemented as an ado
and uses -tabdisp- to do the final table display.  Interestingly,
-tabdisp- exhibits the same behaviour:

. format mdos %tmCY___m

. tabdisp mdos, cell(hosp)

-----------------------
      mdos |   Hospital
-----------+-----------
2006   Apr |          1
2006   May |          0
2006   Jun |          0
...

. format mdos %tmCY____m

. tabdisp mdos, cell(hosp)

----------------------
     mdos |   Hospital
----------+-----------
09jul1961 |          1
10jul1961 |          0
11jul1961 |          0
...

Hopefully I have provided enough detail and examples so that others
may reproduce this and determine if this is indeed a bug.

------------------------
Platform & Version info:

Windows XP sp2

Stata executable
    folder:               K:\Stata9SE\
    name of file:         wsestata.exe
    currently installed:  20 Jul 2007
    latest available:     20 Jul 2007


-- 
David Elliott
*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index