Announcement

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

  • Error when using local and stack

    Hello Stata users. I would appreciate any help. I get error "(memory cleared) invalid syntax r(198); end of do-file r(198) when run this syntax:
    HTML Code:
    use "H:\My Drive\research\climate\HH_data_KZ.dta", clear
    
    local all *
    local omit q23a1_2023 q23a1_2022 q23a1_2021 q23a1_2020 q23a1_2019 q23a1_2018 q23a1_2017 q23a1_2016 q23a1_2015 q23a1_2014 q23a1_2013 q23a2_2023 q23a2_2022 q23a2_2021 q23a2_2020 q23a2_2019 q23a2_2018 q23a2_2017 q23a2_2016 q23a2_2015 q23a2_2014 q23a2_2013 q23a3_2023 q23a3_2022 q23a3_2021 q23a3_2020 q23a3_2019 q23a3_2018 q23a3_2017 q23a3_2016 q23a3_2015 q23a3_2014 q23a3_2013 q23a4_2023 q23a4_2022 q23a4_2021 q23a4_2020 q23a4_2019 q23a4_2018 q23a4_2017 q23a4_2016 q23a4_2015 q23a4_2014 q23a4_2013 q23a5_2023 q23a5_2022 q23a5_2021 q23a5_2020 q23a5_2019 q23a5_2018 q23a5_2017 q23a5_2016 q23a5_2015 q23a5_2014 q23a5_2013 q23a6_2023 q23a6_2022 q23a6_2021 q23a6_2020 q23a6_2019 q23a6_2018 q23a6_2017 q23a6_2016 q23a6_2015 q23a6_2014 q23a6_2013 q23a7_2023 q23a7_2022 q23a7_2021 q23a7_2020 q23a7_2019 q23a7_2018 q23a7_2017 q23a7_2016 q23a7_2015 q23a7_2014 q23a7_2013 q23a8_2023 q23a8_2022 q23a8_2021 q23a8_2020 q23a8_2019 q23a8_2018 q23a8_2017 q23a8_2016 q23a8_2015 q23a8_2014 q23a8_2013
    local all : list all - omit
    di "`all'"
    
    stack `all' q23a1_2023 q23a1_2022 q23a1_2021 q23a1_2020 q23a1_2019 q23a1_2018 q23a1_2017 q23a1_2016 q23a1_2015 q23a1_2014 q23a1_2013 `all' q23a2_2023 q23a2_2022 q23a2_2021 q23a2_2020 q23a2_2019 q23a2_2018 q23a2_2017 q23a2_2016 q23a2_2015 q23a2_2014 q23a2_2013 `all' q23a3_2023 q23a3_2022 q23a3_2021 q23a3_2020 q23a3_2019 q23a3_2018 q23a3_2017 q23a3_2016 q23a3_2015 q23a3_2014 q23a3_2013 `all' q23a4_2023 q23a4_2022 q23a4_2021 q23a4_2020 q23a4_2019 q23a4_2018 q23a4_2017 q23a4_2016 q23a4_2015 q23a4_2014 q23a4_2013 `all' q23a5_2023 q23a5_2022 q23a5_2021 q23a5_2020 q23a5_2019 q23a5_2018 q23a5_2017 q23a5_2016 q23a5_2015 q23a5_2014 q23a5_2013 `all' q23a6_2023 q23a6_2022 q23a6_2021 q23a6_2020 q23a6_2019 q23a6_2018 q23a6_2017 q23a6_2016 q23a6_2015 q23a6_2014 q23a6_2013 `all' q23a7_2023 q23a7_2022 q23a7_2021 q23a7_2020 q23a7_2019 q23a7_2018 q23a7_2017 q23a7_2016 q23a7_2015 q23a7_2014 q23a7_2013 `all' q23a8_2023 q23a8_2022 q23a8_2021 q23a8_2020 q23a8_2019 q23a8_2018 q23a8_2017 q23a8_2016 q23a8_2015 q23a8_2014 q23a8_2013, into(`all' y2023 y2022 y2021 y2020 y2019 y2018 y2017 y2016 y2015 y2014 y2013) clear wide
    rename _stack shock
    Best Regards,
    Dastan

  • #2
    Code:
    local all *
    just copies the single character * to the local macro there named. It does not expand the * into a variable list. That is easily fixed

    Code:
    unab all : *
    does what you want. See also https://journals.sagepub.com/doi/pdf...867X1001000314

    Note also that ds, not and (more flexibly) findname, not are serviceable here. findname is from the Stata Journal.

    Comment


    • #3
      Hello Nick,

      Thanks for your support. But this is not why the error occurs. Since before the firstly publish my post I also used
      HTML Code:
      unab
      This time I also tried your approach again. But the Stata still gives this error " (memory cleared) invalid syntax r(110); end of do-file r(110);"

      When I run this
      Code:
      unab all : *
      local omit q23a1_2023 q23a1_2022 q23a1_2021 q23a1_2020 q23a1_2019 q23a1_2018 q23a1_2017 q23a1_2016 q23a1_2015 q23a1_2014 q23a1_2013 q23a2_2023 q23a2_2022 q23a2_2021 q23a2_2020 q23a2_2019 q23a2_2018 q23a2_2017 q23a2_2016 q23a2_2015 q23a2_2014 q23a2_2013 q23a3_2023 q23a3_2022 q23a3_2021 q23a3_2020 q23a3_2019 q23a3_2018 q23a3_2017 q23a3_2016 q23a3_2015 q23a3_2014 q23a3_2013 q23a4_2023 q23a4_2022 q23a4_2021 q23a4_2020 q23a4_2019 q23a4_2018 q23a4_2017 q23a4_2016 q23a4_2015 q23a4_2014 q23a4_2013 q23a5_2023 q23a5_2022 q23a5_2021 q23a5_2020 q23a5_2019 q23a5_2018 q23a5_2017 q23a5_2016 q23a5_2015 q23a5_2014 q23a5_2013 q23a6_2023 q23a6_2022 q23a6_2021 q23a6_2020 q23a6_2019 q23a6_2018 q23a6_2017 q23a6_2016 q23a6_2015 q23a6_2014 q23a6_2013 q23a7_2023 q23a7_2022 q23a7_2021 q23a7_2020 q23a7_2019 q23a7_2018 q23a7_2017 q23a7_2016 q23a7_2015 q23a7_2014 q23a7_2013 q23a8_2023 q23a8_2022 q23a8_2021 q23a8_2020 q23a8_2019 q23a8_2018 q23a8_2017 q23a8_2016 q23a8_2015 q23a8_2014 q23a8_2013
      local all : list all - omit
      di "`all'"
      Then run this as a second step separately:
      Code:
      stack `all' q23a1_2023 q23a1_2022 q23a1_2021 q23a1_2020 q23a1_2019 q23a1_2018 q23a1_2017 q23a1_2016 q23a1_2015 q23a1_2014 q23a1_2013 `all' q23a2_2023 q23a2_2022 q23a2_2021 q23a2_2020 q23a2_2019 q23a2_2018 q23a2_2017 q23a2_2016 q23a2_2015 q23a2_2014 q23a2_2013 `all' q23a3_2023 q23a3_2022 q23a3_2021 q23a3_2020 q23a3_2019 q23a3_2018 q23a3_2017 q23a3_2016 q23a3_2015 q23a3_2014 q23a3_2013 `all' q23a4_2023 q23a4_2022 q23a4_2021 q23a4_2020 q23a4_2019 q23a4_2018 q23a4_2017 q23a4_2016 q23a4_2015 q23a4_2014 q23a4_2013 `all' q23a5_2023 q23a5_2022 q23a5_2021  q23a5_2020 q23a5_2019 q23a5_2018 q23a5_2017 q23a5_2016 q23a5_2015 q23a5_2014 q23a5_2013 `all' q23a6_2023 q23a6_2022 q23a6_2021 q23a6_2020 q23a6_2019 q23a6_2018 q23a6_2017 q23a6_2016 q23a6_2015 q23a6_2014 q23a6_2013 `all' q23a7_2023 q23a7_2022 q23a7_2021 q23a7_2020 q23a7_2019 q23a7_2018 q23a7_2017 q23a7_2016 q23a7_2015 q23a7_2014 q23a7_2013 `all' q23a8_2023 q23a8_2022 q23a8_2021 q23a8_2020 q23a8_2019 q23a8_2018 q23a8_2017 q23a8_2016 q23a8_2015 q23a8_2014 q23a8_2013, into(`all' y2023 y2022 y2021 y2020 y2019 y2018 y2017 y2016 y2015 y2014 y2013) clear wide
      Then the stat does not give an error. But the variables listed in local `all' are removed. That is, they are not stacked.

      I would appreciate any help.

      Best Regards,
      Dastan
      Last edited by Dastan Aseinov; 08 Dec 2023, 23:32.

      Comment


      • #4
        Originally posted by Dastan Aseinov View Post
        Hello Nick,

        Thanks for your support. But this is not why the error occurs. Since before the firstly publish my post I also used
        HTML Code:
        unab
        This time I also tried your approach again. But the Stata still gives this error " (memory cleared) invalid syntax r(110); end of do-file r(110);"

        When I run this
        Code:
        unab all : *
        local omit q23a1_2023 q23a1_2022 q23a1_2021 q23a1_2020 q23a1_2019 q23a1_2018 q23a1_2017 q23a1_2016 q23a1_2015 q23a1_2014 q23a1_2013 q23a2_2023 q23a2_2022 q23a2_2021 q23a2_2020 q23a2_2019 q23a2_2018 q23a2_2017 q23a2_2016 q23a2_2015 q23a2_2014 q23a2_2013 q23a3_2023 q23a3_2022 q23a3_2021 q23a3_2020 q23a3_2019 q23a3_2018 q23a3_2017 q23a3_2016 q23a3_2015 q23a3_2014 q23a3_2013 q23a4_2023 q23a4_2022 q23a4_2021 q23a4_2020 q23a4_2019 q23a4_2018 q23a4_2017 q23a4_2016 q23a4_2015 q23a4_2014 q23a4_2013 q23a5_2023 q23a5_2022 q23a5_2021 q23a5_2020 q23a5_2019 q23a5_2018 q23a5_2017 q23a5_2016 q23a5_2015 q23a5_2014 q23a5_2013 q23a6_2023 q23a6_2022 q23a6_2021 q23a6_2020 q23a6_2019 q23a6_2018 q23a6_2017 q23a6_2016 q23a6_2015 q23a6_2014 q23a6_2013 q23a7_2023 q23a7_2022 q23a7_2021 q23a7_2020 q23a7_2019 q23a7_2018 q23a7_2017 q23a7_2016 q23a7_2015 q23a7_2014 q23a7_2013 q23a8_2023 q23a8_2022 q23a8_2021 q23a8_2020 q23a8_2019 q23a8_2018 q23a8_2017 q23a8_2016 q23a8_2015 q23a8_2014 q23a8_2013
        local all : list all - omit
        di "`all'"
        Then run this as a second step separately:
        Code:
        stack `all' q23a1_2023 q23a1_2022 q23a1_2021 q23a1_2020 q23a1_2019 q23a1_2018 q23a1_2017 q23a1_2016 q23a1_2015 q23a1_2014 q23a1_2013 `all' q23a2_2023 q23a2_2022 q23a2_2021 q23a2_2020 q23a2_2019 q23a2_2018 q23a2_2017 q23a2_2016 q23a2_2015 q23a2_2014 q23a2_2013 `all' q23a3_2023 q23a3_2022 q23a3_2021 q23a3_2020 q23a3_2019 q23a3_2018 q23a3_2017 q23a3_2016 q23a3_2015 q23a3_2014 q23a3_2013 `all' q23a4_2023 q23a4_2022 q23a4_2021 q23a4_2020 q23a4_2019 q23a4_2018 q23a4_2017 q23a4_2016 q23a4_2015 q23a4_2014 q23a4_2013 `all' q23a5_2023 q23a5_2022 q23a5_2021 q23a5_2020 q23a5_2019 q23a5_2018 q23a5_2017 q23a5_2016 q23a5_2015 q23a5_2014 q23a5_2013 `all' q23a6_2023 q23a6_2022 q23a6_2021 q23a6_2020 q23a6_2019 q23a6_2018 q23a6_2017 q23a6_2016 q23a6_2015 q23a6_2014 q23a6_2013 `all' q23a7_2023 q23a7_2022 q23a7_2021 q23a7_2020 q23a7_2019 q23a7_2018 q23a7_2017 q23a7_2016 q23a7_2015 q23a7_2014 q23a7_2013 `all' q23a8_2023 q23a8_2022 q23a8_2021 q23a8_2020 q23a8_2019 q23a8_2018 q23a8_2017 q23a8_2016 q23a8_2015 q23a8_2014 q23a8_2013, into(`all' y2023 y2022 y2021 y2020 y2019 y2018 y2017 y2016 y2015 y2014 y2013) clear wide
        Then the stat does not give an error. But the variables listed in local `all' are removed. That is, they are not stacked.

        I would appreciate any help.

        Best Regards,
        Dastan
        I have resolved the issue. Upon further investigation, I discovered that the data already contained a "_stack" variable, which was inadvertently included when I stacked other variables during the creation of the data file used in this project.
        I appreciate your willingness to assist, and I apologize for any inconvenience caused. Your support is always valued, and I'll make sure to double-check thoroughly before seeking assistance next time.
        Thank you for your understanding.
        Best regards,
        Dastan

        Comment


        • #5
          Thanks for the closure!

          Comment

          Working...
          X