Announcement

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

  • non r-class program may not set r()

    Dear All,
    I have been trying to estimate a Non Linear Least Square (NLS) IV model using the
    Code:
    bys id: gen runsum_ly = sum(ly)
    gen yb_bar = runsum_ly/m
    gen x_demean = x - xm
    reg ly yb_bar
    predict res, r
    reg ly res x_demean
    predict lyhat
    reg x res x_demean
    predict xhat
    cap nl (y = lyhat*({g}^gap) + {b}*xhat) if m > 1, iter(500) nolog
    if e(converge) == 0 | _rc != 0 {
    ret sca enlsiv_g = .
    ret sca enlsiv_b = .
    }
    else {
    ret sca enlsiv_g = _b[/g]
    ret sca enlsiv_b = _b[/b]
    but been getting this error message: "non r-class program may not set r()." What could be the reason please?. How do I handle with it?.

    Thanks,
    Dapel
    Last edited by Zuhumnan Dapel; 19 Jan 2015, 11:20.

  • #2
    If you want to return something in r(), you need a set up like

    Code:
    program myprogram ,rclass
            ...
            return scalar myscalar = value
    end
    alternatively, you can use Mata to put contents in r(), as in

    Code:
    mata : st_numscalar(r(myscalar), value)
    Best
    Daniel
    Last edited by daniel klein; 19 Jan 2015, 10:46.

    Comment


    • #3
      Thanks Dan. How do I recode these by on any of your suggestions?
      Code:
      ret sca enlsiv_g = _b[/g]
                  ret sca enlsiv_b = _b[/b]
              }
      and
      Code:
      ret sca enlscreiv_g = .
                  ret sca enlscreiv_b = .
      because I got "unexpected end of file" as an error message after using
      Code:
      program myprogram ,rclass
                    ret sca enlsiv_g = .
                  ret sca enlsiv_b = .
              }
              else {
              program myprogram ,rclass
                  ret sca enlsiv_g = _b[/g]
                  ret sca enlsiv_b = _b[/b]
              }
      Last edited by Zuhumnan Dapel; 19 Jan 2015, 11:08.

      Comment


      • #4
        The second instance of

        Code:
        program myprogram ,rclass
        is illegal (and indeed makes no sense). Indeed, the program makes no sense as there is no if block which you need to give meaning to the else block.

        You should back up and tell us what you want to do.

        This looks like "premature programming" to me, that is,

        1. You are trying to write a slightly complicated program before you understand how to write simple ones.

        2. You are writing a program with wired-in variable names when you would be better off writing a do-file.

        Comment


        • #5
          Dear Prof, Thank you for your firm and helpful comments. Here is what I have been wanting to do: to estimate a Non Linear Least Square (NLS) IV model using the
          Code:
          bys id: gen runsum_ly = sum(ly)
          gen yb_bar = runsum_ly/m
          gen x_demean = x - xm
          reg ly yb_bar
          predict res, r
          reg ly res x_demean
          predict lyhat
          reg x res x_demean
          predict xhat
          cap nl (y = lyhat*({g}^gap) + {b}*xhat) if m > 1, iter(500) nolog
          if e(converge) == 0 | _rc != 0 {
          ret sca enlsiv_g = .
          ret sca enlsiv_b = .
          }
          else {
          ret sca enlsiv_g = _b[/g]
          ret sca enlsiv_b = _b[/b]
          but been getting this error message: "non r-class program may not set r()." What could be the reason please? How do I deal with it?

          Thanks,
          Dapel

          Comment


          • #6
            Sorry, but I can't see that you are adding anything to your previous posts. You haven't (yet) shown a need to make this an r-class program. I'd get this working before you try to make it fancier.

            Comment


            • #7
              Sorry Prof. I want to estimate a DPD model, balanced but with gaps. With N=108 and T=24 (actual) and Ti=5 (observed). Is this a bit clearer? First, I used POLS. Here are the

              But we are able to account for change only between two periods. How do we address the nonlinearity across the entire 5 periods within 24 years? I don't know if this is plausible.
              Last edited by Zuhumnan Dapel; 19 Jan 2015, 12:01.

              Comment


              • #8
                Code:
                 preparing the data for the regression analysis
                keep  id, year, pce, cpi
                generate rpce = pce/cpi
                generate ln_rpce=log(rpce)
                tsset id year
                
                the regression for 1980 & 1985
                regress ln_rpce l5.ln_rpce if inrange(year, 1980, 1985), robust
                nlcom  _b[l5.ln_rpce]^(1/5)
                scalar ar_85_80=_b[l5.ln_rpce]^(1/5)
                
                the regression for 1985 & 1992
                regress ln_rpce l7.ln_rpce if inrange(year, 1985, 1992), robust
                nlcom  _b[l7.ln_rpce]^(1/7)
                scalar ar_85_92=_b[l7.ln_rpce]^(1/7)
                
                the regression for 1992 & 1996
                regress ln_rpce l4.ln_rpce if inrange(year, 1992, 1996), robust
                nlcom  _b[l4.ln_rpce]^(1/4)
                scalar ar_92_96=_b[l4.ln_rpce]^(1/4)
                
                
                the regression for 1996 & 2004
                regress ln_rpce l8.ln_rpce if inrange(year, 1996, 2004), robust
                nlcom  _b[l8.ln_rpce]^(1/8)
                scalar ar_96_04=_b[l8.ln_rpce]^(1/8)
                
                view the AR coefficients from the four estimations
                scalar dir

                Comment


                • #9
                  You have spelled out the substantive background, and someone may be able to help. But I am lost on the connection between your latest post and your earlier questions.

                  Comment


                  • #10
                    OK Prof. Here is the difference: I just switched discussion from one estimator, NLS-IV in the initial post to another, POLS in the most recent post. Thanks
                    Last edited by Zuhumnan Dapel; 19 Jan 2015, 12:07.

                    Comment


                    • #11
                      I do not fully get why you think the scalars you are trying to obtain should be put into r(). The code you show in #8 has statements like

                      Code:
                      scalar name = value
                      I cannot see any obvious reason why, in the code in your initial post, you do not simply replace

                      Code:
                      ret sca name = value
                      with

                      Code:
                      scalar name = value
                      just the way you do with your pooled regression models. Why do you want to put them in r() so desperately?

                      Best
                      Daniel

                      Comment


                      • #12
                        After exempting some lines in the initially used codes, I got a some results. I'm reasonable OK now. Thank you all very much!

                        Comment

                        Working...
                        X