Announcement

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

  • Use global macro to call do-file not error

    Dear All,

    I'm trying to use the following code to set up global macro and then call do file based on the macro:
    Code:
    global dataset "passenger"
                if $dataset == "passenger" {
                     do "${indexfolder}/Passenger_code.do"  
                 }
    However, I got the error:
    Code:
    passenger not found
    Couldn't figure out why, could anyone please help?

    Any help will be appreciated!

    Many thanks,
    Craig

  • #2
    Code:
    . global dataset  "passenger"              
    
    . mac list dataset
    dataset:        passenger
    The quotes surround passenger are not assigned to the global macro, so $dataset evaluates to passenger (without quotes), and Stata looks for the variable passenger, which it doesn't find. There are two things you can do:
    Code:
    . global dataset ""passenger"" 
    
    . mac list dataset
    dataset:        "passenger"
    Or
    Code:
    global dataset  "passenger"
    if "$dataset" == "passenger" {
         do "${indexfolder}/Passenger_code.do"  
     }

    Comment


    • #3
      Hi Wouter, thank you very much for your help! It worked perfectly.

      Comment

      Working...
      X