Announcement

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

  • program error: code follows on the same line as open brace

    I have data that has variables from the year 1960 to 1970 currently labeled as YR1960, YR1961, etc., but I want to make stata recognize them as dates and rename. So first i used the command: local i = 1960 , then after that I used the command: foreach var of varlist YR1960 YR1961 YR1962 YR1963 YR1964 YR1965 YR1966 YR1967 YR1968 YR1969 YR1970 {rename `var' yr_`i' local i = `i' + 1}
    But i get the message "program error: code follows on the same line as open brace". What am i doing wrong?

  • #2
    You should edit your code display to respect whatever line breaks you supplied to Stata because at the moment it is all mushed up.

    If you typed

    Code:
    foreach var of varlist YR1960 YR1961 YR1962 YR1963 YR1964 YR1965 YR1966 YR1967 YR1968 YR1969 YR1970 {rename `var' yr_`i' local i = `i' + 1}
    then Stata told you what is wrong: code follows on the same line as open brace. This would be legal:

    Code:
     local i = 1960
    
    foreach var of varlist YR1960 YR1961 YR1962 YR1963 YR1964 YR1965 YR1966 YR1967 YR1968 YR1969 YR1970 {
         rename `var' yr_`i'
         local i = `i' + 1
    }
    But that's all unnecessary.

    Code:
    rename (YR*) (yr_*)
    is shorter code.

    Please note Statalist FAQ Advice #6 (full real names please) and #12 (display code using CODE delimiters).

    Comment


    • #3
      Thank you so much. The new issue is that I get the "type mismatch" error when i try to destring. Some of my cells have this observation ".." and i want to destring and replace them with nothing (just blank cells), using this command:

      foreach var of varlist yr_* {
      replace `var' = "" if `var' == ".."
      destring `var', replace
      }

      what am i doing wrong please?

      Comment

      Working...
      X