Announcement

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

  • How to identify the name of the first variable in a datasheet?

    How can I write a code with the meaning like this:

    HTML Code:
    Use "Path Excel Sheet.xlsx",
    If name of the first variable is X, do "this command", else do "that command"
    I'm stuck at some code identifying the name of the first variable. Many thanks in advance.

  • #2
    Code:
    sysuse auto
    foreach var of varlist _all {
    local vars  "`vars' `var'"
    }
    di "`vars'"
    
    local first: word 1 of `vars'
    di "`first'"
    Code:
    . di "`vars'"
     make price mpg rep78 headroom trunk weight length turn displacement gear_ratio foreign
    
    . local first: word 1 of `vars'
     
    . di "`first'"
    make

    Comment


    • #3
      Thank you very much!

      Comment

      Working...
      X