Announcement

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

  • Creat variable R2 from Nonlinear least-squares estimation

    Hi,

    using a goodness of fit test in form of R2 and AIC I test which hyperbolic discounting model fit my data set on health outcomes best. The models are based on a non linear equation in form of:
    nl (y=(((1+x1)/(1+x2))^(({b0}*H+{b1}*x1+{b2}* x3)/{
    b3}* x4)), vce(cluster ID).

    For the aggregate level (N=99) it worked fine using the command estat ic afterwards, however I want to test the fit of R2 also on an individual level too.
    In the forum I found the idea by U.Kohler in form of:


    . gen r2 = .
    local i 1
    levelsof firm, local(K)
    foreach k of local K {
    regress yvar xvarlist if firm == `k'
    replace r2 = e(r2) in `i++'
    }

    However, STATA does not allow "if" after the nl command. is there another way to deal with this nl form to generate the new R2 variable per individual?

    I would highly appreciate your help!
    Thank you.
    Janin

  • #2
    It's quite wrong to say that if is not allowed with nl. You'll have to explain why you're saying that.

    Comment


    • #3
      Hi Nick,
      thank you for your reply. I am sorry for this wrong statement; I included the "if" incorrect.

      When using the commands mentioned above to generate a new variable for R2 on the individual level and replace the "regress" with my "nl" function, I would process as follows:

      gen r2=.
      local i 1
      levelsof ID, local (K)
      foreach k of K {
      nl (y=(((1+x1)/(1+x2))^(({b0}*H+{b1}*x1+{b2}* x3)/{b3}* x4))) if ID == `k', vce(cluster ID)
      replace r2=e(r2) in ´i++'
      }


      The program now shows me: " invalid syntax; r(198)";

      The background of my study is that each individual (ID; from 1 - 99; storage type float) answered four different scenario questions to reveal their discounting behaviour (captured in variable H). Depending on their discounting behaviour in the four scenarios different discounting models fit better than others and I want to test this by comparing the R2 values per model for each individual seperatly.

      Could the variable ID be a reason for the error?

      Thank you very much!

      Comment


      • #4
        The syntax problem caught here is in an earlier statement.

        Code:
        foreach k of K
        should be

        Code:
        foreach k of local K
        There is at least one more coming up.

        Code:
         ´i++'
        should be

        Code:
        `i++'

        Comment


        • #5
          Thank you very much!

          Comment

          Working...
          X