Announcement

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

  • Fitting NLS model

    Dear All,
    After running this command line
    Code:
    nl(y=({alpha=inv_a}**dj))*dj.y + {gamma=inv_g}*(1-{alpha=inv_a}**dj)/(1-{alpha=inv_a})+({beta_1= inv_b1})*(1-{alpha=inv_a}**dj)/(1-{alpha=inv_a})*x
    I got an error message
    invalid '}'
    . Where
    dj is a variable of the gap size or interval between surveys. It varies. inv_a and inv_are variables of initial values
    . Where have I gone wrong? Please help.

    Thanks,
    Dapel
    Last edited by Zuhumnan Dapel; 21 Feb 2015, 04:01.

  • #2
    ** looks like some Fortran hang-over. Stata has a power operator ^.

    Comment


    • #3
      Thank you! However I still get the same message with the modified version
      Code:
      nl(y=({alpha=inv_a}^dj))*dj.y + {gamma=inv_g}*(1-{alpha=inv_a}^dj)/(1-{alpha=inv_a})+({beta_1= inv_b1})*(1-{alpha=inv_a}^dj)/(1-{alpha=inv_a})*x

      Comment


      • #4
        What's

        Code:
        dj.y
        ?

        Comment


        • #5
          Thanks. Its a variable that define lags. The data is for 1980, 1985, 1992, 1996, 2004 and 2010. Therefore the
          dj
          for 1980 and 1985 is 5; for 1985 and 1992 is 7 and so on. Is this OK?

          Comment


          • #6
            Thanks, but I am not asking about dj but about what that dot . is doing there. I am not fluent in factor variable notation, but it looks like a typo to me.

            Comment


            • #7
              OK. Thanks. Since the
              dj
              between 1980 and 1985 is 5, instate of lagged 5, i.e. L5.y, I use
              Code:
              dj.y

              Comment


              • #8
                Have you tried that? Looks like fantasy syntax to me. I would be interested in being wrong.

                Code:
                 
                gen whatever = dj.y

                Comment


                • #9
                  Thanks. Here is what I got
                  Code:
                  . gen lagged_y = dj.y
                  dj:  operator invalid
                  r(198);

                  Comment


                  • #10
                    My point precisely; it is not legal syntax. I don't understand your intent well-enough to suggest better syntax, but you should not be surprised at getting an error message.

                    Comment


                    • #11
                      If the dataset were 1980, 1986, 1992, 1998, 2004 and 2010; with a constant interval of 6, one can will not need
                      Code:
                      dj.y
                      Instead I will comfortably use L6.y. But dataset is 1980, 1985, 1992, 1996, 2004 and 2010 such that the lags vary. I don't know if this is a bit clearer.

                      Comment


                      • #12
                        You could ignore the unequal spacing and tsset in terms of sequence, not time. For lags varying between 4 years and 8 years I would find that hard to defend. There must be context here on how people fit whatever model it is in whatever literature it is, but (1) you need to tell us and (2) I won't have an answer, I suspect.

                        The main question it seems to me is not one of Stata syntax now. Your model evidently adjusts for differing gaps by differing powers dj but still contains a previous known value for the previously known time a varying time ago. That has to be revisited in terms of the underlying mathematics, it would seem.
                        Last edited by Nick Cox; 21 Feb 2015, 08:45.

                        Comment


                        • #13
                          We have a few problems here. One is that we've drifted from the original symptom, the failure of nl to correctly interpret the right brace "}". Our hope is that resolving other identified syntax issues will resolve that issue as a byproduct. But that may not happen.

                          I would suggest that Mr. Dapel revise his nl command to a very simple version and build it up step-by-step, making sure each step works as he expects before adding additional complexity. Start with something like
                          Code:
                          nl( y = ({alpha=inv_a}^dj) )
                          and procede from there to
                          Code:
                          nl( y = ({alpha=inv_a}^dj)*dj.y )
                          and so on.

                          With that said, I also agree with Mr. Cox that "dj.y" is not correct Stata syntax. L6.y is the syntax for the application of the "lag 6 periods" operator to the variable y. But dj is a variable, not an operator, so "dj.y" does not make any sense. I also suspect the parentheses are not correctly wrapped around the full argument to the nl command, but I could be wrong about that.

                          With more information, such as a view of some of the data, I, or someone else, might be able to understand what has to be done to express the model Mr. Dapel seeks in terms of the data he has. But lacking that, I've reached the extent of my ability to help with this problem, as I think Mr. Cox is saying for himself as well.

                          Comment


                          • #14
                            I have confirmed that there is a problem with parenthesis balance in the revised nl command given at #3 above. In the code block below, I've broken the command across several lines (which would not directly work in Stata of course) and aligned the various parts of the command to make the structure easier to follow. We can see that the left parenthesis in nl( is matched by )*dy.j when it should match a (missing) parenthesis at the end of the argument list, following the x.
                            Code:
                            nl(y=
                                                   (  {alpha=inv_a}^dj)                  
                            ) * dj.y 
                            +  {gamma=inv_g}     * (1-{alpha=inv_a}^dj) / (1-{alpha=inv_a})
                            + ({beta_1= inv_b1}) * (1-{alpha=inv_a}^dj) / (1-{alpha=inv_a}) * x
                            I hope this is helpful.

                            Comment


                            • #15
                              Dear William,
                              Thank you very much for the detailed response. I have adjusted the code to suit the suggestion you provided although I still get the same error message
                              Code:
                              nl(y=({alpha=inv_a}^dj)) * dj.y + {gamma=inv_g} * (1-{alpha=inv_a}^dj) / (1-{alpha=inv_a})+({beta_1= inv_b1})*(1-{alpha=inv_a}^dj) / (1-{alpha=inv_a}) * x)

                              Comment

                              Working...
                              X