Announcement

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

  • Date variables as headers in the output of table command

    Hello all,

    When I put a date variable in the table command, the resulted table contains the double/float values as the value headers. I found no workaround.

    For example, "table (some_cat_var) (start_date)" would give me something like this, where start_date is a float variable with %td format and some_cat_var is a numeric variable with labels of its own.
    Click image for larger version

Name:	ss.png
Views:	1
Size:	6.1 KB
ID:	1688496



    Edit:: I see that labmask-ing serves the purpose, I am attaching the code.

    gen start_date_str = string(start_date, "%td")
    labmask start_date, values(start_date_str)

    Is there an easier way?

    Thanks
    Last edited by Naazmus Sakib; 07 Nov 2022, 13:02.

  • #2
    Code:
    format start_date %td
    table (some_cat_var) (start_date)

    Comment


    • #3
      Originally posted by Andrew Musau View Post
      Code:
      format start_date %td
      table (some_cat_var) (start_date)
      I am sorry, it does not work. If I might add, going back to an older version (I use 17) seems to only half-work
      Code:
      version 16: table (some_cat_var) (start_date)
      It outputs the labels as proper dates, as attached in the screenshot.
      Click image for larger version

Name:	ss2.png
Views:	1
Size:	3.7 KB
ID:	1688510



      But when I try to collect the table (which is the main purpose of sticking to table), it outputs the numerical values.
      Last edited by Naazmus Sakib; 07 Nov 2022, 13:22.

      Comment


      • #4
        I cannot reproduce this in V17.

        Code:
        webuse sp500, clear
        keep in 1/5
        g profit=change>0
        table (profit) (date)
        Res.:

        Code:
        . webuse sp500, clear
        (S&P 500)
        
        . keep in 1/5
        (243 observations deleted)
        
        . g profit=change>0
        
        . table (profit) (date)
        
        -----------------------------------------------------------------
                  |                         Date                         
           profit | 02jan2001  03jan2001  04jan2001  05jan2001  08jan2001
        ----------+------------------------------------------------------
                0 |                               1          1          1
                1 |         1          1                                 
        -----------------------------------------------------------------
        Try updating your installation.

        Code:
        update all

        Comment


        • #5
          Originally posted by Andrew Musau View Post
          I cannot reproduce this in V17.

          Code:
          webuse sp500, clear
          keep in 1/5
          g profit=change>0
          table (profit) (date)
          Res.:

          Code:
          . webuse sp500, clear
          (S&P 500)
          
          . keep in 1/5
          (243 observations deleted)
          
          . g profit=change>0
          
          . table (profit) (date)
          
          -----------------------------------------------------------------
          | Date
          profit | 02jan2001 03jan2001 04jan2001 05jan2001 08jan2001
          ----------+------------------------------------------------------
          0 | 1 1 1
          1 | 1 1
          -----------------------------------------------------------------
          Try updating your installation.

          Code:
          update all
          Updating worked like a charm! Thank you!

          Comment

          Working...
          X