Announcement

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

  • nonlinear simultaneous equations nlsur for each observation

    Hi, everyone!
    I'm trying to solve the simultaneous system of two equation to get the daily data of variables va and siga (given the initial values va_init and siga_init).
    a = {va} * normal((log({va}/c)+(b+0.5*({siga}^2)))/ {siga}) -c* exp(-(b))* normal(((log({va}/c)+(d+0.5*({siga}^2)))/ {siga})-{siga})
    d = ({va}/a)* normal((log({va}/c)+(b+0.5*({siga}^2)))/ {siga})*{siga}

    I'm using -nlsur in stata to get them, but for some reason the formula cannot calculate these value for each observation (which is needed here), but only for the group.

    Here is the formula I use:
    nlsur (a = {va} * normal((log({va}/c)+(b+0.5*({siga}^2)))/ {siga}) -c* exp(-(b))* normal(((log({va}/c)+(d+0.5*({siga}^2)))/ {siga})-{siga})) (d = ({va}/a)* normal((log({va}/c)+(b+0.5*({siga}^2)))/ {siga})*{siga}), initial(va va_init[_n] siga siga_init[_n])


    If I try to calculate it the following way:
    by one, sort: nlsur (a = {va} * normal((log({va}/c)+(b+0.5*({siga}^2)))/ {siga}) -c* exp(-(b))* normal(((log({va}/c)+(d+0.5*({siga}^2)))/ {siga})-{siga})) (d = ({va}/a)* normal((log({va}/c)+(b+0.5*({siga}^2)))/ {siga})*{siga}), initial(va va_init[_n] siga siga_init[_n])
    --> I get the error: cannot have fewer observations than parameters

    But this is exactly what I need to calculate:
    Does anyone know the solution for my problem?

    I also attach the example file, so that you can try it.
    Attached Files

  • #2
    nlsur is an estimation command, with the syntax you provide it will give you a single value of va and siga for the whole model. It is not a simultaenous equation solver. I wonder why you thought of nlsur to address this problem.
    From the syntax, the value of siga and va for each observation seems to depend on other variables only. I suppose there isn't a closed form solution for the system and that's why you tried this.

    Have you seen this FAQ?


    http://www.stata.com/support/faqs/pr...ear-equations/
    Jorge Eduardo Pérez Pérez
    www.jorgeperezperez.com

    Comment


    • #3
      Originally posted by Jorge Eduardo Perez Perez View Post
      nlsur is an estimation command, with the syntax you provide it will give you a single value of va and siga for the whole model. It is not a simultaenous equation solver. I wonder why you thought of nlsur to address this problem.
      From the syntax, the value of siga and va for each observation seems to depend on other variables only. I suppose there isn't a closed form solution for the system and that's why you tried this.

      Have you seen this FAQ?


      http://www.stata.com/support/faqs/pr...ear-equations/
      Hi Jorge Eduardo Pérez Pérez,
      thank you for the reply.

      Yes, I saw this FAQ about nl. So you think nl will be a better choice of the command for this kind of model?

      I tried
      nl (y= (a - {va} * normal((log({va}/c)+(b+0.5*({siga}^2)))/ {siga}) +c* exp(-(b))* normal(((log({va}/c)+(d+0.5*({siga}^2)))/ {siga})-{siga}))^2 + (d - ({va}/a)* normal((log({va}/c)+(b+0.5*({siga}^2)))/ {siga})*{siga})^2)
      where y is the vector of zeroes, but the result is the same:

      in this case I get the error "y has zero variance", and for one observation - cannot have fewer observations than parameters....

      Last edited by Aurora13; 24 Apr 2014, 01:47.

      Comment


      • #4
        Originally posted by Aurora13 View Post
        Yes, I saw this FAQ about nl. So you think nl will be a better choice of the command for this kind of model?
        Yes, according to the FAQ nl is the way to go here.

        Originally posted by Aurora13 View Post
        in this case I get the error "y has zero variance"
        The FAQ states that you have to create y as to have the value 1 in the first observation. Did you do that? Otherwise y will have zero variance and the command will fail.
        Jorge Eduardo Pérez Pérez
        www.jorgeperezperez.com

        Comment


        • #5
          Originally posted by Jorge Eduardo Perez Perez View Post

          Yes, according to the FAQ nl is the way to go here.

          The FAQ states that you have to create y as to have the value 1 in the first observation. Did you do that? Otherwise y will have zero variance and the command will fail.
          Hi, I changed y for the value1 in the first observation, but unfortunately the initial problem remained the same:
          It still gives only the single va and siga for the model, while I need distinct values for each observation...

          Comment


          • #6
            Are you trying to solve a system of two equations for two unknowns? In that case, rather than playing tricks with -nl- or -nlsur-, you might want to consider using the -solvenl- function in Mata assuming you have Stata 13. It's designed specifically for what you want to do. Type

            help solvenl


            Tom

            Comment

            Working...
            X