Announcement

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

  • tabstat

    Dear All,

    I want Stata to tell me the number of observation for a large list of variables by region. The first set of commands works:

    Code:
    *first set
    tabstat `xvars', by(Region) s(n)
    tabstat `raw', by(Region) s(n)
    
    gen Region_n = 2
    replace Region_n = 1 if Region == "Europe"
    
    *second set
    tabstat Region_n, by(`xvars') s(n)
    tabstat Region_n, by(`raw') s(n)
    The second set returns:

    Code:
    . tabstat Region_n, by(`xvars') s(n)
    by():  too many variables specified

    xvars and raw are variable list. The reason I run the second set is that the first set shortens the variables names to an unreadable format. So I hope to get the full variable name out of the second set of commands, but I get the error. Is there a way to overwrite this?

    I have two regions and want for the variable lists know, how many I have by region. Seems like a straight forward problem?

    I appreciate your help!


  • #2
    it sounds as though the output format is the problem; if that is so, try adding "c(s)" as an option to your first set of commands

    Comment


    • #3
      It's easy and documented: the by() option supports single variable names only. To get what you want

      Code:
      egen group = group(`xvars'), label
      tabstat ..., by(group)
      Last edited by Nick Cox; 04 Jul 2016, 07:30.

      Comment


      • #4
        Dear Rich Goldstein

        yes, sort of. The thing is, that it now does not print the variable names. See the attached graph. Do you know how I can tell Stata to still print the variable names?







        Attached Files

        Comment


        • #5
          Nick Cox :
          thanks for the hint. Maybe I am getting you wrong, but you suggested to group by Region right? This worked, but I still have the same problem now, in that I cannot read the name of my variables. Or am I completely misunderstanding your point?
          Click image for larger version

Name:	varnames.jpg
Views:	1
Size:	209.1 KB
ID:	1347981

          Comment


          • #6
            double posted sorry...
            Last edited by Jannic Cutura; 04 Jul 2016, 08:53.

            Comment


            • #7
              remark: I just found fsum, which does want I want for my sum commands (that is print long variable names). is there something similar for tabstat?

              Comment


              • #8
                Second remark:

                Code:
                tabstat  `xvars' , by(Region) s(n) col(stat) varwidth(16)
                sort of solves the problem. Using a the varwidfth command suggested by Clyde Schechter here:
                HTML Code:
                http://www.statalist.org/forums/forum/general-stata-discussion/general/485147-tabstat-long-variable-names
                in that sense: Problem Solved!

                Thanks everybody!

                Comment


                • #9
                  On #5: No, I didn't suggest that and I am at a loss to see why you thought that.

                  I am pointing out that if you want the argument of the by() option to be two or more variables, then that won't work; but you can overcome the problem by grouping those variables into one.

                  Comment

                  Working...
                  X