Announcement

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

  • Incorrect number of variables after describe?

    Hello,

    I am using Stata 15.1 MP. After I run the display command on varlist, I expect r(k) to contain the number of vars in varlist. Instead it seems to contain the number of variables in the entire dataset (I'm guessing).

    Code:
    . describe bene* , si
    bene1  bene2  bene3  bene4  bene5
    
    . display r(k)
    330
    I was expecting r(k) to be 5. Am I wrong? What other function can I use to get the number of variables in a varlist that may be abbreviated as above.

    Thanks.
    'Alim

  • #2
    You are wrong. r(k) is always the number of variables in the data set. If you want a count of the number of variables in the varlist, just do:

    Code:
    ds bene* // (not describe)
    display `:word count `r(varlist)''
    Added: The PDF documentation states that r(k) is the number of variables, without specifying whether it refers to the varlist or the entire data set. In context of the other things returned by -describe-, it makes sense to presume that r(k) refers to the entire dataset, as everything else there clearly does. Still, it wouldn't hurt if StataCorp clarified this in the future.

    Comment


    • #3
      Dear Clyde,
      Thanks for clarifying. I'd say though that it makes sense to presume that r(k) will contain the number of variables that describe found and has shown.
      I will use the the code you provided, with thanks.
      Best,
      'Alim

      Comment

      Working...
      X