Announcement

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

  • loop

    Hello everybody,
    I am a beginner in stata programming. However, I am looking for help in programming a loop.
    I would like to replicate a number of regressions by simply changing some options and saving the regression results in a table where each column represents the results of a regression.

    For example, I want to replicate a number of times:

    xtdpdgmm y x, gmm (y, l (i j) c m (l)) iv (i.Year, l (p q) m (l)) twostep overid nocons
    underid
    underid, overid

    changing i, j, p and q (where i <j and p <q) according to some predefined ranges. And saving the results of each regression in a column of a table, if they pass the underidentification and overidentification tests indicated below.

    Can someone help me to compose a program that does this routine?

  • #2
    It sounds like you wanna do a parallel list, but I guess my question for you, is "Is this really worth it"? Like are you running simulations..? You say you wanna store them if they pass the overidentification tests, but why not store all of them?

    Comment


    • #3
      hi Jared,

      in fact there is a small error in the regression, which however does not change my question. here is the loop that should explain my intentions:

      forvalues i = 1/12 {
      forvalues j = 2/14 {
      forvalues p = 1/4 {
      forvalues q = 1/6 {
      xtdpdgmm y x, gmm (y, l (i j) c m (l)) iv (x, l (p q) m (l)) twostep overid nocons
      underid
      underid, overid
      }
      }
      }
      }

      I would like to collect in a table the results of all the regressions, the pvalues of the tests and the relative values i, j, p and q, if the regressions pass the under and overidentification tests.

      I hope I have been clearer.

      thank you
      L

      Comment


      • #4
        No I understood you, my point is (based off this new code you've provided) that the code you've provided will literally run 3774 times. Don't believe me? Do
        Code:
        cls
        
        forvalues i = 1/12 {
        forvalues j = 2/14 {
        forvalues p = 1/4 {
        forvalues q = 1/6 {
        
        di `i' `j' `p' `q'
        }
        }
        }
        }
        You're essentially running 3774 regressions. This will decidedly not fit in a table, no matter whether or not the criteria pass. In fact, let's be kind and say both the tests pass half of the times. That's 1872 lines in a table you've got!! Let's say they pass a quarter of the time. You have 936 lines in a table. If these tests passed 5% of the time, you have 187 lines.

        The real question I'm asking you, is are you sure that this is what you want? Is this your intended outcome? If so, then I guess we can proceed, but I wanted to be sure that you get what you're really asking.

        Comment


        • #5
          Hi Jared

          forgive the delay. You are definitely right. Too many calculations.
          The intervals I had indicated for i, j, p and q were only indicative. In reality, the values are:

          forvalues i = 1/2 {
          forvalues j = 2/6 {
          forvalues p = 1/2 {
          forvalues q = 2/6 {
          xtdpdgmm y x, gmm (y, l (i j) c m (l)) iv (x, l (p q) m (l)) twostep overid nocons
          underid
          underid, overid
          }
          }
          }
          }

          Perhaps these values also generate many regressions; it is for this reason that I would like to save only the regressions that pass the two tests.

          can you help me?

          thank you
          L

          Comment

          Working...
          X