Announcement

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

  • Why varname in stata syntax command is not parsed correctly?

    I am a bit frustrated by the following and not sure if I am missing something. varname (unlike varlist) cannot be parsed after syntax command


    Code:
    . qui webuse auto, clear
    
    cap prog drop ExperimentVarname
    prog ExperimentVarname
      1.   syntax varname, filename(string) varlabel(string)
      2.   dis "varname: `varname', filename: `filename', varlabel: `varlabel'"
      3. end
    
    cap prog drop ExperimentVarlist
    prog ExperimentVarlist
    1.   syntax varlist, filename(string) varlabel(string)
    2.   dis "varlist: `varlist', filename: `filename', varlabel: `varlabel'"
    3. end
    
    .
    ExperimentVarname price, filename("myfile1") varlabel("label1")
    varname: , filename: myfile1, varlabel: label1
    
    ExperimentVarlist price, filename("myfile2") varlabel("label2")
    varlist: price, filename: myfile2, varlabel: label2
    .
    Last edited by Islam Moh Khalil; 25 Feb 2023, 02:18.

  • #2
    You need to ask to look at the contents of local macro varlist.

    Although syntax varname is permitted, the variable name found still is mapped to local macro varlist.

    This may seem inconsistent but the help does say that

    After the syntax command, the resulting varlist is returned in `varlist'
    Last edited by Nick Cox; 25 Feb 2023, 02:52.

    Comment


    • #3
      Thanks, Nick Cox. for the clarification. Probably, I overlooked that while reading the help.

      Comment

      Working...
      X