Announcement

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

  • Invalid syntax when using user-written program

    Hi all!

    I have a panel of countries and some macroeconomic variables and I'm trying to code a program in Stata to graph them and when I try to see if it worked I get an invalid syntax error message. More specifically, here is the program and the last line is where I'm trying to test it with two variables of my data set and a country (one of many that I've tried):

    Code:
    cap program drop graphing
    program define graphing
        version 1.0
        syntax [if] [in] [, country(string) variable1(varname) variable2(varname)]
        
        preserve
        keep if countryname=="`country'"
    
        
        graph twoway (line `variable1' date)///
        (line  `variable2' date)
        
        graph save "${output}\Series\figure_`country'_`variable1'_`variable2'.gph ", replace 
        restore
    
    end
    
    
    graphing, country("Argentina") variable1(dginz) variable2(inflows_gdp)
    Then I get the following error:

    invalid syntax
    r(198);
    I put a set trace on before running that last line and the error occurs exactly after I write this line (the program doesn't even start), which leads me to think the problem is in the line where I try to test the program but I'm not really sure and I can't find why would it be wrong. So any help is extremely welcome!!


  • #2
    The problem is that -version 1.0- statement. The program is telling Stata to use the syntax interpreter from version 1 of Stata. Now, I only go back to version 4, but my guess is that the -syntax- command did not exist in Stata version 1. I'm not even sure version 1 of Stata had ado files. Anyway, take that out and you're good to go.

    Comment


    • #3
      Clyde has been around much longer than I have; I started around the transition between Stata 9 and 10 (which, by the way, introduced the graphic editor). Anyway, I am pretty sure there was no syntax in Stata until version 5 or 6. What's more, there was no version command before Stata 3. Stata did have the program statement and there were ado-files right from the beginning.


      Caterina might be interested in reading about the different meanings of version (also: here).
      Last edited by daniel klein; 11 Mar 2021, 23:58.

      Comment


      • #4
        Many thanks to both!!! It worked both erasing the version line or updating the version number. And thank you daniel klein for the links!

        Comment

        Working...
        X