Announcement

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

  • Command Describe does not return r(varlist) in Stata 16?

    Dear Stata users,

    I want to get a series of varlist name in my task. So I resort to -describe- in order to get return of r(varlist). However in practice, it seems that -describe- dose not provide such a return. Hope someone can help me, thank you very much.

    Here are what I cited from help file of -describe-:
    describe stores the following in r():

    Scalars
    r(N) number of observations
    r(k) number of variables
    r(width) width of dataset
    r(changed) flag indicating data have changed since last saved

    Macros
    r(datalabel) dataset label
    r(varlist) variables in dataset (if varlist specified)
    r(sortlist) variables by which data are sorted (if varlist specified)
    Code:
    sysuse auto
    describe mpg price weight length
    return list

  • #2
    Sorry I forgot to add option of "varlist" after -descibe-. The correct code should be:
    Code:
    describe mpg price weight length, varlist

    Comment


    • #3
      Slightly offtopic but hopefully still helpful:

      I often see people use commands such as ds or describeto obtain a list of variables and/or the number of observations and/or the number of variables in the dataset. There is nothing wrong with that but these commands come with some overhead. Also, we usually want the results in local macros not in r() which implies an additional step. I just wanted to point to a less known command, unab, that can be used to put a list of variable names into a local macro more directly. Also, the number of observations and the number of variables in the current dataset are directly accessible through c(N) and c(k), respectively.

      Comment


      • #4
        Thank you very much daniel klein. It is very helpful.

        Comment

        Working...
        X