Announcement

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

  • how to find out variable order number

    Hi there
    Is there a quick way of determining the order number of a variable? For example, if "gender" is the 58th variable in the variable order, is this stated somewhere?
    Thanks

  • #2
    A variable name is one word. So use the -word()- function.

    Code:
    sysuse auto, clear
    qui ds
    di word("`r(varlist)'", 11)
    Res.:

    Code:
    . di word("`r(varlist)'", 11)
    gear_ratio
    
    .

    Comment


    • #3
      This demonstrates the reverse of Andrew's solution - giving the position of a particular variable name.
      Code:
      . sysuse auto, clear
      (1978 automobile data)
      
      . qui ds
      
      . local vars `r(varlist)'
      
      . local num : list posof "gear_ratio" in vars
      
      . display `num'
      11
      
      .

      Comment


      • #4
        Many thanks, both!

        Comment

        Working...
        X