Announcement

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

  • Custome made program that loads dataset and keeps variables give "nor variables defined" error

    So I want to make a program that loads a dataset, and optinally keep some variables. I am unable to copy the code from the server, so I am giving a small example

    Code:
    program load_dataset
    syntax anything [, keep_list(varlist)] use "`anything'" if !missing("`keep_list'") {
    [INDENT=2]keep `keep_list'[/INDENT]
    }
    end
    I then run the code (the global is a string with pathname)

    Code:
    load_dataset $sample_data, keep_list(year family income)
    And then get the error:
    "no variables defined" (error in option keep_list())

    I suspect it is because these variables do no yet exist, which they of course won't until I load the data set. Is there something I am missing? Or do I have to solve it in some other way, for example passing the varlist as a string instead?

  • #2
    Specify namelist instead.

    Comment


    • #3
      Originally posted by Nick Cox View Post
      Specify namelist instead.
      Nick Cox to the rescue as always. Is there somewhere I can read in more detail about syntax? I have read the https://www.stata.com/manuals13/psyntax.pdf, but I stille feel that I am trying things blindly. Or maybe I should just reread it a couple of more times.

      Comment


      • #4
        That's the documentation. I don't know any other source. In essence once you;re writing programs StataCorp assumes that you want technical documentation with fewer jokes or elementary examples.

        It's a while back, but despite a history of programming in other languages, my first two years with Stata were focused on do files. The challenge about programs strict sense is to learn several new things at the same time.

        I don't know why people so often cite the manuals for version 13, except that Google brings them up and there is a feedback loop evident. https://www.stata.com/manuals/psyntax.pdf is the current version and also accessible in your Stata (otherwise, following the FAQ Advice, you should be explaining which version you are using). In this particular case, I don't think that entry has changed much, if at all.

        Comment

        Working...
        X