Announcement

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

  • Syntax error on a foreach and cannot understand why

    Hello! I am a first time poster so I apologize for any mistakes or lack of etiquette. I am new to STATA so the FAQ did not make too much sense to me but I will try my best!

    I have tried the following lines:
    forvalues `i = 2011(1)2023{
    2. egen y‘`i’ = rowtotal(y‘`i’_*)
    3. replace y‘`i’=y‘`i’/12
    4. drop y‘`i’_*
    5. }
    As well as
    . forvalues i = 2011(1)2023{
    2. egen y`‘i’ = rowtotal(y`‘i’_*)
    3. replace y‘`i’=y‘`i’/12
    4. drop y‘`i’_*
    5. }

    As well as
    . forvalues i = 2011(1)2023{
    2. egen y‘`i’ = rowtotal(y‘`i’_*)
    3. replace y‘`i’=y‘`i’/12
    4. drop y‘`i’_*
    5. }

    And I am getting
    "invalid syntax" r(198);
    in response to all them.

    I would appreciate any help and to provide any extra information needed!

    Thank you!

  • #2
    You seem to have one too many `. Try something like the following, maybe copy and paste for the first pass.
    Code:
    forvalues i = 2011/2023 {
        egen double y`i' = rowtotal(y`i'_*)
        quietly replace y`i' = y`i' / 12
        drop y`i'_*
    }

    Comment


    • #3
      thank you! worked great

      Comment


      • #4
        I am new to STATA so the FAQ did not make too much sense to me
        Indeed, but please skim and skip your way to #18.

        Good that you solved your problem!

        Comment

        Working...
        X