Announcement

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

  • Loop varsoc



    Hi every body:

    I have a pilled set of time series from which I am trying to run a varsoc. They are time series od different variables an countires. Everything is xtset.


    I am trying with this:


    foreach x in varlist Y Yx D Px PX e M m X x PM R Kp KP{
    by Cou: varsoc x
    }

    but doen´t work. I thing it repeats the var soc for my variable x over and over...


    I´ve also been exploring the possibility of using levels of, but no fruitfull results.


    thanks for any advise.


  • #2
    Although I know nothing about the -varsoc- command, I don't think that's the source of the problem. You have set up a loop in which you want x to vary over a list of variables, but your reference to it inside that loop, x, is incorrect and also happens to be one of the variable names you want to loop over. To refer to the loop index, you have to say `x', not x. Also pay attention to that left quote--it is the on the key to the left of the 1 key on a US keyboard. Also, -foreach...varlist- requires of, not in.* So what you want is:

    Code:
    foreach x of varlist Y Yx D Px PX e M m X x PM R Kp KP {
        by Cou: varsoc `x'
    }
    As an aside, having variable names that differ only by the use of upper and lower case in certain characters is a set-up for making mistakes. Unless the letters themselves have mnemonic value and the upper and lower case has some meaningful significance, it is just too easy to get these things wrong, especially in long lists.

    Comment


    • #3
      Thank you so much.

      Now I am having a different problem. With other parts of the code.

      Please if you could help.

      http://www.statalist.org/forums/foru...30-optimal-lag


      Thanks once again.

      Comment


      • #4
        Manuel,

        I have just responded to your other post. Suggestion: give your posts more informative titles. When I first saw the other post, "Optimal Lag" I didn't even bother to read it because it looked like it was not about anything I'm interested in. In actual fact, your post is about iteratively building up a matrix. The word lag doesn't even occur in the content of the post! Had you called it "iteratively building up a matrix" I would have read it and responded when you first posted it.

        Even this thread is not well titled. It has nothing to do with -varsoc-; it's a question about writing loops. The word loop is what could my eye and led me to read it (and respond). But I almost passed it over. When I see a post about a command I've never heard of, I usually pass it by.

        So do choose titles that accurately reflect the problem you are having. You'll get better answers, sooner.

        Comment


        • #5
          Thnak you, for both your replies.

          I will change the tittles, so that they may help other people.

          Thanks again.

          Comment

          Working...
          X