Announcement

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

  • Content of r(k) after describe: how to count variables?

    A Statalist post from 2011 lists several options for counting variables in a varlist. Quote:

    After

    . describe <varlist>

    r(k) contains the number of variables in <varlist>.
    This does not match what I get in Stata 14.2. In the example below, r(k) stores the number of variables in the auto data, not the number of variables in the describe command. Has the behavior of describe changed since 2011?
    Code:
    . sysuse auto
    (1978 Automobile Data)
    
    . d make price
    
                  storage   display    value
    variable name   type    format     label      variable label
    ----------------------------------------------------------------------------------------
    make            str18   %-18s                 Make and Model
    price           int     %8.0gc                Price
    
    . return list
    
    scalars:
                r(changed) =  0
                  r(width) =  43
                      r(k) =  12
                      r(N) =  74
    help describe is not clear on this because the exact meaning of "number of variables" in the excerpt below is not known. It could be the number of variables in the dataset or the number of variables in the describe command. From the help file:

    describe stores the following in r():

    Scalars
    r(N) number of observations
    r(k) number of variables
    For the record, another option in the above-mentioned Statalist post yields the correct number of variables:
    Code:
    . unab vars : make price
    
    . di `: word count `vars''
    2

  • #2
    I just tested on Stata 11.2, which is the oldest version accessible at the moment, and the behaviour is as at present.

    Implication: I was wrong in that post. Sorry.

    describe counts variables in the dataset, regardless of an explicit varlist.

    Comment


    • #3
      Thank you.

      Comment

      Working...
      X