Announcement

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

  • Newbie question on invalid syntax

    I'm using Stata SE 12.0 for Windows 64 bit and I'm completely new at Stata.

    I'm loading up a simple .do file from a particular project and it keeps giving me invalid syntax errors.

    The offending lines tend to be something like this:

    ". label define label_state AK "Alaska"
    invalid syntax

    It appears Stata doesn't like a non-value "AK" in the middle of the label but the file I was given looks as if there are other files with very similar syntax.

    Am I not turning off a particular Stata setting or am I using the wrong Stata version to handle something like this?

  • #2
    Gary:
    I'm under the impression that Stata chokes on:
    Code:
    label_state AK
    as it expects and underscore in between:
    Code:
    label_state_AK
    .
    As a toy example, you may want to run what follows:
    Code:
    set obs 1
    g label_state AK=1 // this line of code is wrong and, as expected, Stata complains "too many variables specified" r(103);
    g label_state_AK=1 //this line of code is right
    label define label_state_AK 1 "Alaska"
    label value label_state_AK label_state_AK
    Kind regards,
    Carlo
    (StataNow 18.5)

    Comment


    • #3
      My guess is different. Carlo's alternative syntax is certainly legal but in practice it would be very strange to define a separate set of value labels with just one value label, unless Sarah Palin has something to do with it.

      I think you are trying to define value labels for string variables, but Stata has no such idea. You could use a string variable or attach "Alaska" etc. as value labels for a numeric variable, but Stata does not support this.

      Your syntax error does not diagnose the major difficulty, but is implied by it.

      My story does not tally with the impression that these do files (should have) worked elsewhere, but I am at a loss to see why.

      I am confident that this has nothing to do with Stata version and it's not tunable. There is only one legal syntax conceivable here and it is documented under help label

      Comment


      • #4
        Mmm, at this point, I contacted the people who made this and asked them if they can get back to me. Meanwhile, the files are located here.
        I'm confused as to what to do with them.

        The do file:
        http://nces.ed.gov/ipeds/datacenter/...Data_Stata.zip

        The csv file:
        http://nces.ed.gov/ipeds/datacenter/data/HD2007.zip

        Comment


        • #5
          Both look like data files to me.

          Comment


          • #6
            Neither of the two linked ZIP archives contains a do-file. When I download them, both contain csv files.

            Comment


            • #7
              Oops, here's the do file.

              http://nces.ed.gov/ipeds/datacenter/...2007_Stata.zip

              Comment


              • #8
                Sure enough, the syntax is there and the do-file would be predicted to fail where you say it does. Also, there are lots of similar statements.

                At this point I have to guess that someone was translating from some other language and that this was never tested with Stata.

                Comment


                • #9
                  That's good. At least it confirms I'm not crazy. Thanks for the help, everybody.

                  Comment


                  • #10
                    You could try just cloning the do file and leaving out any label define lblname text ... commands. Integers are OK, but not arbitrary text.

                    Comment

                    Working...
                    X