Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down on April 23, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: st: nlsuraids need help with AIDS model error please


From   "Liu, Pei Chun" <pliu@mail.smu.edu>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   RE: st: nlsuraids need help with AIDS model error please
Date   Wed, 11 Jul 2012 06:34:12 +0000

Thank you so much Brian. It's working like a charm now!!!

Pei

________________________________________
From: owner-statalist@hsphsun2.harvard.edu [owner-statalist@hsphsun2.harvard.edu] on behalf of Brian P. Poi [bpoi@stata.com]
Sent: Tuesday, July 10, 2012 8:57 AM
To: statalist@hsphsun2.harvard.edu
Subject: Re: st: nlsuraids need help with AIDS model error please

On 07/10/2012 03:47 AM, Liu, Pei Chun wrote:
> Dear Statlist,
>
> I need help with the AIDS model I am running below. With 3 goods, I get "nlsuraids returned 199 verify that nlsuraids is a function evaluator program" after running it.
>
>
>
> program nlsuraids12;
>   version 11.2;
>
>   syntax varlist(min=6 max=6) if , at(name);
>   tokenize `varlist';
>   args w1 w2 lnp1 lnp2 lnp3 lnm;
>
>   tempname a1 a2 a3;
>   scalar `a1' = `at'[1,1];
>   scalar `a2' = `at'[1,2];
>   scalar `a3' = 1 - `a1' - `a2';
>
>   tempname b1 b2;
>   scalar `b1' = `at'[1,3];
>   scalar `b2' = `at'[1,4];
>
>   tempname g11 g12 g13;
>   tempname g21 g22 g23;
>   tempname g31 g32 g33;
>
>   scalar `g11' = `at'[1,5];
>   scalar `g12' = `at'[1,6];
>   scalar `g13' =-`g11'-`g12';
>
>
>   scalar `g21' = `g12';
>   scalar `g22' = `at'[1,7];
>   scalar `g23' = -`g21'-`g22';
>
>
>   scalar `g31' = `g13';
>   scalar `g32' = `g23';
>
>
>   quietly {
>    tempvar lnpindex;
>    gen double `lnpindex' = 5 + `a1'*`lnp1' + `a2'*`lnp2' +///
>          `a3'*`lnp3';
>    forvalues i=1/3 {
>     forvalues j=1/3 {
>      replace `lnpindex' = `lnpindex'+///
>         0.5*`g`i'`j''*`lnp`i''*`lnp`j'';
>     };
>    };
>    replace `w1' = `a1' + `g11'*`lnp1' + `g12'*`lnp2' + ///
>        `g13'*`lnp3'+ `b1'*(`lnm' - `lnpindex');
>    replace `w2' = `a2' + `g21'*`lnp1' + `g22'*`lnp2' + ///
>        `g23'*`lnp3'+ `b2'*(`lnm' - `lnpindex');
>
>   };
>
> end;
>
> nlsur aids @ w1 w2 lnp1 lnp2 lnp3 lnm, parameters(a1 a2 b1 b2 g11 g12 g22) neq(2) ifgnls;
>

Pei,

I see three problems here.  First, you name your program nlsuraids12, but you tell -nlsur- to look for a different program named nlsuraids.  Your -nlsur- command should be

. nlsur aids12 @ w1 w2 lnp1 lnp2 lnp3 lnm, parameters(a1 a2 b1 b2 g11 g12 g22) neq(2) ifgnls;

Also, you never define `g33', but you need that parameter to compute the price index.  Right after

. scalar `g32' = `g23';

add the line

. scalar `g33' = -`g13'-`g23';

Third, you use semicolons for end-of-line delimiters.  That's fine, but if you do that then you must use them with every line, so the lines

quietly {
forvalues i=1/3 {
forvalues j=1/3 {

should be

quietly {;
forvalues i=1/3 {;
forvalues j=1/3 {;

Plus, if you use semicolon delimiters, then you do not need to use the "///" to spread long statements across multiple lines.

Below my signature is a version of your program that does work.

    -- Brian Poi
    -- bpoi@stata.com


clear all

#delimit ;
program nlsuraids12;
        version 11.2;

        syntax varlist(min=6 max=6) if , at(name);
        tokenize `varlist';
        args w1 w2 lnp1 lnp2 lnp3 lnm;

        tempname a1 a2 a3;
        scalar `a1' = `at'[1,1];
        scalar `a2' = `at'[1,2];
        scalar `a3' = 1 - `a1' - `a2';

        tempname b1 b2;
        scalar `b1' = `at'[1,3];
        scalar `b2' = `at'[1,4];

        tempname g11 g12 g13;
        tempname g21 g22 g23;
        tempname g31 g32 g33;

        scalar `g11' = `at'[1,5];
        scalar `g12' = `at'[1,6];
        scalar `g13' =-`g11'-`g12';


        scalar `g21' = `g12';
        scalar `g22' = `at'[1,7];
        scalar `g23' = -`g21'-`g22';


        scalar `g31' = `g13';
        scalar `g32' = `g23';
        scalar `g33' = -`g13'-`g23';

        quietly {;
                tempvar lnpindex;
                gen double `lnpindex' = 5 + `a1'*`lnp1' + `a2'*`lnp2' +
                                        `a3'*`lnp3';
                forvalues i=1/3 {;
                        forvalues j=1/3 {;
                                replace `lnpindex' = `lnpindex'+
                                                0.5*`g`i'`j''*`lnp`i''*`lnp`j'';
                        };
                };
                replace `w1' = `a1' + `g11'*`lnp1' + `g12'*`lnp2' +
                        `g13'*`lnp3'+ `b1'*(`lnm' - `lnpindex');
                replace `w2' = `a2' + `g21'*`lnp1' + `g22'*`lnp2' +
                        `g23'*`lnp3'+ `b2'*(`lnm' - `lnpindex');
        };

end;

// random data to test with
set seed 1;
set obs 1000;
foreach x in w1 w2 lnp1 lnp2 lnp3 lnm {;
        gen `x' = runiform();
};
nlsur aids12 @ w1 w2 lnp1 lnp2 lnp3 lnm, parameters(a1 a2 b1 b2 g11 g12 g22) neq(2) ifgnls;




*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index