Announcement

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

  • replaceing variable names with labels in -tabstat-

    I am tabulating responses to a set of survey questions and I would like to replace the variable name, the question number, with the variable label. my command and result is:

    tabstat q30_1 q30_3 q30_4 q30_5, columns(statistics) statistics(sum mean)


    variable | sum mean
    -------------+--------------------
    q30_1 | 29 .1790123
    q30_3 | 48 .2962963
    q30_4 | 18 .1111111
    q30_5 | 69 .4259259

    ----------------------------------

    The respective variable labels q30_* are: President / CEO / Vice President / Director
    Manager
    Administrative Assistant / Clerical
    None of the above

    Thanks,
    David


  • #2
    I'm pretty sure that -tabstat- simply can't do what you're asking for with the data arrayed this way. You can get something like what you're asking for as follows:

    Code:
    // CREATE AN OBSERVATION ID VARIABLE (IF IT DOESN'T ALREADY EXIST)
    gen obs_no = _n
    reshape long q30_, i(obs_no) j(officer)
    label define officer 1 "President" 3 "CEO" 4 "Vice President" 5 "Director"
    label values officer officer
    tabstat q30_, by(officer) statistics(sum mean)

    Comment


    • #3
      This can also be achieved using estpost and esttab (or estout), which is a generic solution. I'm including a couple common options I use when I do this: use of quotes ("), fmt, varwidth, noobs, and LABEL. The label option is was achieves the OP's desired task. The last line saves the desired table in a format that can be opened directly by a word processor (e.g., Microsoft Word), including through the clickable link.

      Code:
      use http://www.stata-press.com/data/r7/emd.dta
      quietly estpost tabstat precipitation income_pc, columns(statistics) statistics(sum mean)
      esttab ., cells("sum(fmt(%9.0f)) mean(fmt(%9.1f))") label varwidth(30) noobs
      esttab using descriptives.rtf, cells("sum(fmt(%9.0f)) mean(fmt(%9.1f))") label varwidth(30) noobs replace

      Comment


      • #4
        You can send the output and variable labels to MS Word just in one line using asdoc (available on SSC for download).
        In your case, you need to add just asdoc to the beginning of the line and label in the options

        Code:
        asdoc tabstat q30_1 q30_3 q30_4 q30_5,  stat(sum mean) label
        For those who are not yet familiar with asdoc, asdoc can be downloaded from SSC and can be used with almost all Stata commands. Here is a short blog post that shows how asdoc can be used with any Stata command http://fintechprofessor.com/2018/02/...basic-example/. You can also watch several YouTube videos that show the use of asdoc https://www.youtube.com/watch?v=zdI6...LwodAk2oqLYhr-

        Code:
        *For installation of the stable version
        ssc install asdoc
        
        * For installation of the new beta version
        net install asdoc, from(http://fintechprofessor.com) replace
        help asdoc
        Last edited by Attaullah Shah; 15 Feb 2019, 20:08.
        Regards
        --------------------------------------------------
        Attaullah Shah, PhD.
        Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
        FinTechProfessor.com
        https://asdocx.com
        Check out my asdoc program, which sends outputs to MS Word.
        For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

        Comment


        • #5
          Hi Ataullah,
          How can i keep the variable labels in the matrix generated by asdoc?

          Comment


          • #6
            With the tab command, asdoc creates a Stata matrix. The column and row names / labels are processed inside Mata functions. Therefore, it is hard to get the two in one place.

            You might be interested in knowing that asdocx leaves behind a fully-developed Mata matrix which can be further modified. See the following example:
            Code:
            asdocx tab rep78, label replace
            
            * The mata matrix looks like this
            
              0 |1                                  2               3               4 
            ----+----------------------------------------------------------------------------
              1 |Repair Record 1978             Freq.         Percent            Cum. 
            ----+----------------------------------------------------------------------------
              2 |1                                  2            2.90            2.90 
              3 |2                                  8           11.59           14.49 
              4 |3                                 30           43.48           57.97 
              5 |4                                 18           26.09           84.06 
              6 |5                                 11           15.94          100.00 
              7 |Total                             69          100.00                 
            ---------------------------------------------------------------------------------
            
            
             * If we wished to change label for column two from Freq. to Frequency
            
            . asdocx addcell, data(Frequency) col(2) row(1)
            
            
              Table: Results
              0 |1                                    2              3              4 
            ----+-----------------------------------------------------------------------------
              1 |Repair Record 1978           Frequency        Percent           Cum. 
            ----+-----------------------------------------------------------------------------
              2 |1                                    2           2.90           2.90 
              3 |2                                    8          11.59          14.49 
              4 |3                                   30          43.48          57.97 
              5 |4                                   18          26.09          84.06 
              6 |5                                   11          15.94         100.00 
              7 |Total                               69         100.00                
            ----------------------------------------------------------------------------------
            Regards
            --------------------------------------------------
            Attaullah Shah, PhD.
            Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
            FinTechProfessor.com
            https://asdocx.com
            Check out my asdoc program, which sends outputs to MS Word.
            For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

            Comment


            • #7
              Thanks. Where can I find the asdocx ado file?

              Comment


              • #8
                See the link in #2 for how to obtain asdocx (money first).

                Comment


                • #9
                  To get asdocx, please follow this link https://fintechprofessor.com/asdocx/ . asdocx is currently available at $9.99 only. With the asdocx membership, you get :
                  • Life-time license to use
                  • All future updates
                  • All premium templates / plugins.
                  Regards
                  --------------------------------------------------
                  Attaullah Shah, PhD.
                  Professor of Finance, Institute of Management Sciences Peshawar, Pakistan
                  FinTechProfessor.com
                  https://asdocx.com
                  Check out my asdoc program, which sends outputs to MS Word.
                  For more flexibility, consider using asdocx which can send Stata outputs to MS Word, Excel, LaTeX, or HTML.

                  Comment

                  Working...
                  X