Announcement

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

  • Using external data that's not called in by nl command in function evaluator program.

    Hi,

    I am using function evaluator program for an nl command, and would like to call in an external dataset that's not called in by nl command in the function evaulator program by merge command. However, whenever I put in merge command inside the function evaluator program, I get the error message
    nlauto_extdta2 returned 110
    starting values invalid or some RHS variables have missing values
    r(480);
    Here's the code I used:
    program nlauto_extdta2

    syntax varlist(min=4 max=4) [aw fw iw] if, at(name)
    local price: word 1 of `varlist'
    local cons: word 2 of `varlist'
    local x: word 3 of `varlist'
    local id: word 4 of `varlist'

    *parameters
    forvalues i = 1(1)2{
    tempname b`i'
    scalar `b`i'' = `at'[1,`i']
    }


    merge 1:1 id using autodata.dta
    assert _merge==3

    replace `x' = x `if'


    replace `price' = `b1'*`cons' + `b2'*`x' `if'


    end
    where I execute this program with the following commands:
    sysuse auto, clear

    gen id=_n
    gen x=uniform()
    keep id x
    save autodata.dta, replace

    sysuse auto, clear
    gen cons = 1
    gen id=_n
    gen x=uniform()

    matrix ivals = J(1,2,1)

    do nlauto_extdta2.do

    nl auto_extdta2 @ price cons x id, nparameters(2) initial(ivals)

    If I do not include the boldface part in the function evaluator program, the nl command would work and give me estimates, but once I include those commands, the error message appears. I would appreciate any ideas and suggestions. Thank you.

    Sincerely,
    Soo

  • #2
    Dear Soo, once you do the merge, check the _merge variable and then drop it! Otherwise there is a merge error and the estimation can't proceed. Best, Sergiy Radyakin

    Code:
    (obs = 74)
    
    Iteration 0:  residual SS =  6.29e+08
    Iteration 1:  residual SS =  6.29e+08
    
          Source |       SS       df       MS
    -------------+------------------------------         Number of obs =        74
           Model |   5875621.9     1   5875621.9         R-squared     =    0.0093
        Residual |   629189774    72  8738746.86         Adj R-squared =   -0.0045
    -------------+------------------------------         Root MSE      =  2956.137
           Total |   635065396    73  8699525.97         Res. dev.     =  1390.738
    
    ------------------------------------------------------------------------------
           price |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
             /b1 |   6609.843   641.9222    10.30   0.000     5330.194    7889.492
             /b2 |  -994.4592   1212.787    -0.82   0.415    -3412.107    1423.188
    ------------------------------------------------------------------------------
      Parameter b1 taken as constant term in model & ANOVA table
    
    .
    end of do-file

    Comment


    • #3
      Hi Sergiy,

      Thanks so much for your help! I've been struggling with it for days and this is truly mind blowing.

      Best,
      Soo

      Comment


      • #4
        If you are using Stata 13 (and I think this works in version 12 also), you can do the merge with the following syntax:

        Code:
        merge 1:1 id using autodata.dta, assert(match) nogenerate
        and then you will not need the assert statement, nor will you need a command to drop _merge (as it will not be created in the first place).

        Comment

        Working...
        X