Announcement

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

  • r(198) error in Stata

    Hi,

    I'm trying to set up a foreach loop in Stata to merge and append 4 waves of data. The problem is that every time I try to do this I get the r(198) invalid error message relating to the second variable in the use list. At first I thought it was a problem with the particular variable that was second but I've tried lots of different combinations and no matter which variable I have 2nd on the list, I get this error message for it.

    The code from the .do file is below. Any help would be greatly appreciated.




    foreach w in a b c d {
    use `w'_hidp `w'_sex `w'_jbstat `w'_aidhrs `w'_jbterm1///
    `w'_jbterm2 `w'_jbsemp `w'_jbsect `w'_jbsectpub `w'_jbhrs `w'_j2has `w'_ccare ///
    `w'_howlng `w'_livewith `w'_employ `w'_hhtype_dv `w'_jbseg_dv `w'_netinc1 ///
    `w'_qfhigh `w'_racel pidp `w'_mastat_dv ///
    using "$dir/`w'_indresp", clear
    gen wave = strpos("abcd","`w'")
    rename `w'_* *
    save `w'junk.dta, replace
    }

    foreach w in a b c {
    append using `w'junk.dta
    }
    sort pidp wave
    save abcd_long.dta, replace



    Thanks

  • #2
    Is this the exact code you used, pasted directly from your do-file or the Results window? The problem that jumps out at my eye is that the /// at the end of the first line of the -use- command is not preceded by any whitespace. That is a syntax error. Whether that is the only problem with your code, I cannot say without a compatible data set to test things on. But if that is your actual code (and not a mis-typed copy), fix that first and see what happens.

    Comment


    • #3
      Eleanor Carey , compare:
      Code:
      foreach v in 1 2 {
        display "`v'"///
           "`v'"
      }
      with
      Code:
      foreach v in 1 2 {
        display "`v'" ///
           "`v'"
      }
      Best, Sergiy Radyakin
      Last edited by Sergiy Radyakin; 10 Jun 2015, 11:24. Reason: reduced example to minimal

      Comment

      Working...
      X