Announcement

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

  • Syntax problem in stochastic dominance test

    I have a syntax error message for this ado file and cant find where the problem is. It tests for dominance up to the third order using income data in the analysis of poverty. Sorry I can't provide a minimal working example as I'm not sure where the error is. It displays up to the line " display "Maximum test point is " `zmax' " . A previous error was spotted by a forum member and fixed.


    #delimit ;
    program define dom; * syntax is dom var1 wgt1 var2 wgt2 zmax #test-points;
    version 6.0;
    local x1 `1';
    local wgt1 `2';
    local x2 `3';
    local wgt2 `4';
    local zmax = `5';
    local num = `6';
    summarize `x1', meanonly;
    local min1 = r(min);
    summarize `x2', meanonly;
    local min2 = r(min);
    local min = max(`min1',`min2');
    local inter = (`zmax'-`min')/(`num'-1);
    local min = `min' + `inter'; * Don’t start at very end of tail;
    local inter = (`zmax'-`min')/(`num'-1);
    local done = 0;
    local s = 1;
    tempvar ind;
    display " ";
    display "Minimum test point is " `min';
    display " ";
    display "Maximum test point is " `zmax';
    display " "; if `zmax' <= `min' {;
    local done = 1;
    display " ";
    display in red "Error: " in yellow "Max test point is not larger than
    min test point!";
    display " ";
    };
    while `done' == 0 {;
    display " ";
    display "Order " `s';
    display "Z D1 D2 t-statistic";
    local alpha = `s' - 1;
    local i = 1;
    local z = `min';
    quietly gen `ind' = .;
    while `z' <= `zmax' {;
    quietly fgt `x1' `wgt1' `z' `alpha';
    local D1 = ${D`s'};
    local VD1 = ${VD`s'};
    quietly fgt `x2' `wgt2' `z' `alpha';
    local D2 = ${D`s'};
    local VD2 = ${VD`s'};
    local t = (`D2'-`D1')/sqrt(`VD1'+`VD2');
    display %5.4f `z' " " %5.4f `D1' " " %5.4f `D2' " "
    %4.2f `t';
    local ind0 = 1.5;
    if `t' >= 1.96 {; local ind0 = 1; };
    if `t' <= -1.96 {; local ind0 = 2; };
    quietly replace `ind' = `ind0' if _n==`i';
    local z = `z' + `inter';
    local i = `i' + 1;
    };
    summarize `ind', meanonly;
    if r(mean) == 1 {; local done = 1;
    global Dorder = -`s';
    display "";
    display "Dominance achieved at order " `s';
    local s = 1;};
    if r(mean) == 2 {; local done = 1;
    global Dorder = `s';
    display "";
    display "Dominance achieved at order " `s';
    local s = 1;};
    if `s' >= 3 {; local done = 1;
    global Dorder = 0;
    display "";
    display "Dominance not achieved up to order
    3";};
    drop `ind';
    local s = `s' + 1;
    };
    end;

  • #2
    I forgot to say, if it helps, that this was written for stata 6 and I'm using 12.

    Comment


    • #3
      have you tried using -trace- to help find the problem (also read about -tracedepth-)?

      Comment


      • #4
        I didnt know about that. I've tried it now thanks, this is the problem


        - quietly fgt `x1' `wgt1' `z' `alpha'
        = quietly fgt exp1 1 16.12011821453388 0
        ---------------------------------------------------------------------------------------------- begin fgt ---
        - version 12.0 local var `1'
        = version 12.0 local var exp1
        invalid syntax
        ------------------------------------------------------------------------------------------------ end fgt ---

        Comment


        • #5
          You are using a user-written program -fgt- within another -dom-. See FAQ Advice on being expected to explain that. The first two lines of that program, as copied to your machine, have been run together. The command -local- should be on a separate line.

          Comment


          • #6
            Thanks for your help. That explained a lot.

            Comment


            • #7
              dear all,
              Can u tell me the Stata syntax of testing the stochastic dominance (of poverty) with ttest. After proving 1st order dominance (one region over the other) via plotting the cumulative distribution functions (cdfs), I want to test the statistical significance of differences in these two cdfs (ttest) between the poverty line, say, $10 and $40. How to do it? Nick Cox

              Comment


              • #8
                Sorry, but you shouldn't read my contribution to this thread as implying expertise in poverty analysis. I am not aware that you can compare cdfs using a t test, but what you need here I can't say.

                Comment


                • #9
                  understood, Nick Cox sir.
                  just let me put it differently if u could help here. There is this user-written programme which is quoted in #1 as well used to check dominance of one distribution over other.
                  Code:
                  #delimit ;
                  program define dom; * syntax is dom var1 wgt1 var2 wgt2 zmax #test-points;
                   version 16.0;
                   local x1 `1';
                   local wgt1 `2';
                   local x2 `3';
                   local wgt2 `4';
                   local zmax = `5';
                   local num = `6';
                   summarize `x1', meanonly;
                   local min1 = r(min);
                   summarize `x2', meanonly;
                   local min2 = r(min);
                   local min = max(`min1',`min2');
                   local inter = (`zmax'-`min')/(`num'-1);
                   local min = `min’ + `inter’; 
                   * Don’t start at very end of tail;
                   local inter = (`zmax'-`min')/(`num'-1);
                   local done = 0;
                   local s = 1;
                   tempvar ind;
                  display " ";
                  display "Minimum test point is " `min';
                  display " ";
                  display "Maximum test point is " `zmax';
                  display " ";
                   if `zmax' <= `min' {;
                   local done = 1;
                   display " ";
                   display in red "Error: " in yellow "Max test point is not larger than
                  min test point!";
                   display " ";
                   };
                   while `done' == 0 {;
                   display " ";
                   display "Order " `s';
                   display "Z D1 D2 t-statistic";
                   local alpha = `s' - 1;
                   local i = 1;
                   local z = `min';
                   quietly gen `ind' = .;
                   while `z' <= `zmax' {;
                   quietly fgt `x1' `wgt1' `z' `alpha';
                   local D1 = ${D`s'};
                   local VD1 = ${VD`s'};
                   quietly fgt `x2' `wgt2' `z' `alpha';
                   local D2 = ${D`s'};
                   local VD2 = ${VD`s'};
                   local t = (`D2'-`D1')/sqrt(`VD1'+`VD2');
                   display %5.4f `z' " " %5.4f `D1' " " %5.4f `D2' " "
                  %4.2f `t';
                   local ind0 = 1.5;
                   if `t' >= 1.96 {; local ind0 = 1; };
                   if `t' <= -1.96 {; local ind0 = 2; };
                   quietly replace `ind' = `ind0' if _n==`i';
                   local z = `z' + `inter';
                   local i = `i' + 1;
                   };
                   summarize `ind', meanonly;
                   if r(mean) == 1 {; local done = 1;
                   global Dorder = -`s';
                   display "";
                   display "Dominance achieved at order " `s';
                   local s = 1;};
                   if r(mean) == 2 {; local done = 1;
                   global Dorder = `s';
                   display "";
                   display "Dominance achieved at order " `s';
                   local s = 1;};
                   if `s' >= 3 {; local done = 1;
                   global Dorder = 0;
                   display "";
                   display "Dominance not achieved up to order
                  3";};
                   drop `ind';
                   local s = `s' + 1;
                   };
                  end;
                  It works fine in the sense that there is no error in execution but when I apply it to data with the command
                  Code:
                  use c:\copen\data\expend
                  gen pcexp = hhexpend / hhsize
                  sum pcexp, detail
                  scalar zmax = r(p50)
                  preserve
                  keep if region==1
                  keep pcexp hhsize
                  rename pcexp pcexdop1
                  rename hhsize hhsize1
                  save c:\temp\temp, replace
                  restore
                  preserve
                  keep if region==2
                  keep pcexp hhsize
                  merge using c:\temp\temp
                  dom pcexp1 hhsize1 pcexp hhsize zmax 40
                  restore
                  everything works fine until the last command
                  Code:
                  dom pcexp1 hhsize1 pcexp hhsize zmax 40
                  Stata shows this error
                  Code:
                  `min’ invalid name
                  if it is possible can u tell me anything about the issue/error? this final command tests the statistical significance of dominance using t-statistic which is what I require

                  Comment


                  • #10
                    What I said earlier remains true. On this occasion

                    Code:
                    local min = `min’ + `inter’;
                    can be spotted as having the wrong quotation marks, which should be
                    Code:
                      
                      local min = `min' + `inter';
                    and so you should check for similar errors in the code

                    Comment


                    • #11
                      Thanks a lot, Mr. Nick. Will check the rest errors.

                      Comment


                      • #12
                        Sorry for bothering you one final time, Nick Cox. Just need one clarification on one of the codes if it possible for u and I understand u not having "expertise in poverty analysis".
                        So as u had mentioned in #5 that it consisted of user-written -fgt- and -dom-, the problem is with -fgt program..The code for fgt is given as
                        Code:
                        * syntax is "fgt var wgt z alpha"
                        #delimit ;
                        program define fgt;
                         version 6.0
                         local var `1';
                         local wgt `2';
                         local z = `3';
                         local alpha = `4';
                         local s = `alpha' + 1;
                         local afac = round(exp(lnfact(`alpha')),1);
                         tempvar N ind gap ngap;
                         quietly gen `gap' = `z' - `var';
                         quietly gen `ind' = 0;
                         quietly replace `ind' = 1 if `gap' >= 0;
                         quietly gen `ngap' = `gap' / `z';
                         quietly replace `gap' = (`gap'^`alpha') * `ind';
                         quietly replace `ngap' = (`ngap'^`alpha') * `ind';
                         summarize `gap' [aw=`wgt'], meanonly;
                         local dhat = r(mean) / `afac';
                         summarize `ngap' [aw=`wgt'], meanonly;
                         local phat = r(mean);
                         quietly replace `gap' = `gap' ^ 2;
                         summarize `gap' [aw=`wgt'], meanonly;
                         local vdhat= (1/r(N))*((r(mean)/(`afac'^2)) - (`dhat'^2));
                         global P`alpha' = `phat';
                         global D`s' = `dhat';
                         global VD`s' = `vdhat';
                         display "P"`alpha' " = " `phat';
                         display "D"`s' " = " `dhat';
                         display "VD"`s' " = " `vdhat';
                        end;
                        After running the Stata command for fgt
                        Code:
                        preserve
                        keep if region==1
                        fgt pcexp hhsize z 0
                        scalar D1 = $D1
                        scalar VD1 = $VD1
                        restore
                        preserve
                        keep if region==2
                        fgt pcexp hhsize z 0
                        scalar D2 = $D1
                        scalar VD2 = $VD1
                        restore
                        scalar tstat12 = (D1-D2)/sqrt(VD1+VD2)
                        display tstat12
                        it shows the error
                        Code:
                        fgt pcexp hhsize z 0
                        invalid syntax
                        the same error is seen in -dom- after ur correction helped in step #10. Is it possible that u can locate any coding mistake in -fgt program code? I tried but couldn't figure out.

                        Comment

                        Working...
                        X