Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

RE: st: RE: programming question


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   RE: st: RE: programming question
Date   Wed, 3 Jul 2002 18:28:21 +0100

Maureen Paul
> 
> Thanks for the reply. I will try what you suggested. I have included 
> a good portion of the propramme so illustrate what I am trying to do. 
> The error occurs here:
> - while `k' <= `x' {
> - tempvar y`k'var1q
> - ge `y`k'var1q' = `y`k'iqq' * `2' `if'
> INVALID SYNTAX
>   local k = `k' + 1
>   }
> 
> but it works fine if I remove the bit where I inlcude the 
> heteroscedasticity bit.
> 
>   noisily oprobit `*' `if' [`weight'`exp']
> 
>    
>   scalar `catnum'=e(k_cat)
>   scalar `degreef'=e(df_m)
>   scalar `obs' = e(N)
> 
>   predict `scoreqq' `if', xb
>   ge `scor_uqq' = `scoreqq'
>   replace `scor_uqq' =. if `1'==. 
>   ge `scor_nqq' = `scor_uqq'
>   replace `scor_nqq' = `scor_uqq' - _b[`2'] if `2'==1 
>   replace `scor_uqq' = `scor_nqq' + _b[`2'] if `2'==0
>   
>   ge `diffqq1' = normprob(_b[_cut1]-`scor_uqq') - normprob(_b[_cut1]-
> `scor_nqq')  if `1'~=.
>   
>   su `diffqq1' `if'
>   scalar `diff1' = r(mean)
>   scalar `check' = `diff1'
>   su `1' `if'
>   scalar `depmin' = r(min)
>   scalar `depmax' = r(max)
> 
>   ge `wj' = ( _b[_cut1] - `scoreqq' ) `if'
>   ge `PHIwj' = normprob(`wj') `if'
>   ge `phiwj' = (1/sqrt(2*_pi)) * exp( (`wj'^2)/-2 ) `if'
>   
>   ge `eqq'=( -1 * `phiwj' ) / (`PHIwj')  if `1'==`depmin' & `ifexp' 
>   ge `e2qq'=( -1 * `wj' * `phiwj' ) / ( `PHIwj' ) if `1'==`depmin' & 
> `ifexp'   
>   ge `e3qq'=( -1 * (`wj'^2) * `phiwj' ) / ( `PHIwj' ) if 
> `1'==`depmin' & `ifexp'   
>   ge `e4qq'=( -1 * (`wj'^3) * `phiwj' ) / ( `PHIwj' ) if 
> `1'==`depmin' & `ifexp'     
>   
>   su `1' if `1'>`depmin' & `ifexp' 
>   local j = r(min)               /* set j to 2nd lowest value of dep 
> var */
>   local x = 2
> 
>   
>    while `j' <= `depmax' { 
> 		
> 	local xless1 = `x'-1
> 	drop `diffqq1' 
> 	if `j' < `depmax' {
> 		ge `diffqq1' = ( normprob(_b[_cut`x']-`scor_uqq') - 
> normprob(_b[_cut`x']-`scor_nqq') ) /*
> 			 */  - ( normprob(_b[_cut`xless1']-`scor_uqq') - 
> normprob(_b[_cut`xless1']-`scor_nqq') ) /*
> 			 */ if `1'~=. 
> 	} 
> 	else { 
> 		ge `diffqq1' = normprob(`scor_uqq'-_b[_cut`xless1']) - 
> normprob(`scor_nqq'-_b[_cut`xless1']) if `1'~=. 
> 	} 
> 	su `diffqq1' `if' 
> 	local diff`x' = r(mean) 
> 	scalar `check' = `check' + `diff`x'' 
> 
> 	rename `wj' `wj_1' 
> 	rename `phiwj' `phiwj_1'
> 	rename `PHIwj' `PHIwj_1' 
> 	
> 	if `j'~=`depmax' { 
> 		ge `wj' = ( _b[_cut`x'] - `scoreqq' ) `if' 
> 		ge `phiwj' = (1/sqrt(2*_pi)) * exp( (`wj'^2)/-2 ) `if' 
> 		ge `PHIwj' = normprob(`wj') `if' 
> 	} 
> 	else { 
> 		ge `wj' = 0 
> 		ge `phiwj' = 0 
> 		ge `PHIwj' = 1 
> 	} 
> 
> 	replace `eqq'=( `phiwj_1' - `phiwj' ) / ( `PHIwj' - `PHIwj_1' ) if 
> `1'==`j' & `ifexp' 
> 	replace `e2qq'=( (`wj_1' * `phiwj_1') - (`wj' * `phiwj') ) /*
> 		     */  / ( `PHIwj' - `PHIwj_1' )        if 
> `1'==`j' & `ifexp'   
> 	replace `e3qq'=( ((`wj_1'^2) * `phiwj_1') - ((`wj'^2) * `phiwj') ) 
> /* 
> 		     */  / ( `PHIwj' - `PHIwj_1' )        if 
> `1'==`j' & `ifexp'  
> 	replace `e4qq'=( ((`wj_1'^3) * `phiwj_1') - ((`wj'^3) * `phiwj') ) 
> /*
> 		    */  / ( `PHIwj' - `PHIwj_1' )        if 
> `1'==`j' & `ifexp'    
> 	
> 	if `j'~=`depmax' { 
> 		tempvar y`x'iqq      
> 		ge `y`x'iqq' = 0 `if' 
> 		replace `y`x'iqq'=( `phiwj' ) / ( `PHIwj' - 
> `PHIwj_1' ) if `1'==`j' 
> & `ifexp'
> 	} 
> 
> 	if `x'~=2 { 
> 		replace `y`xless1'iqq'=( -1 * `phiwj_1' ) / ( 
> `PHIwj' - `PHIwj_1' ) 
> /*
> 					*/	if `1'==`j' & `ifexp' 
> 	} 
> 	
> 	su `1' if `1'>`j' & `ifexp' 
> 	local j = r(min)       /* replace j with next value of dep var */
> 	local x=`x'+1 
> 	drop `wj_1' `phiwj_1' `PHIwj_1'
>   }                         
>   
> 
>   replace `e3qq' = `e3qq' + (2 * `eqq') `if'
>   replace `e4qq' = `e4qq' + (3 * `e2qq') `if'
> 
>   local x=`xless1'                   /* set x to the number of cuts 
> */
>   local onecut=( `x' == 1 )          /* onecut=1 if only one cut    
> */
> 
>   ge `regdepqq'=1 `if'
>   ge `escscq'=`eqq' * `scoreqq' * `scoreqq' `if'
>   ge `esc3qq'=`escscq' * `scoreqq' `if'
>   ge `esc4qq'=`esc3qq' * `scoreqq' `if'
>   ge `e2scscq'=`e2qq' * `scoreqq' * `scoreqq' `if'
> 
>   local n=2
>   local lastvar=0
>   while "``n''" ~= "" & `lastvar' ~= 1  {
> 	local m=`n'-1
> 	tempvar evar`m'qq
> 	ge `evar`m'qq' = `eqq' * ``n'' `if'
> 	local n = `n'+1
> 	local lastvar = ( "``n''" == "if" )
>   }
> 
>   local k=2
>   while "``k''" ~= "" {
> 	local kless1 = `k' - 1
> 	tempvar e2var`kless1'q
> 	ge `e2var`kless1'q' = `e2qq' * ``k'' `if'
>        
> if "`heteroscedasticity'" ~= "" { parse "`heteroscedasticity'", 
> parse(" ") 
> 	    			tempvar hetvar
> 	   			local namevar "`1'" 
> 			      foreach var of varlist `varlist' {
> 							  if 
> "`var'"=="``k''" {ge `hetvar'=`e2var`kless1'q'' `if'}	    
>                                  
> 	      }
> 
> 	local k = `k'+1
> 
>   }
> 
> 
>   local k=2
>   while `k' <= `x' {
> 	tempvar y`k'var1q
> 	ge `y`k'var1q' = `y`k'iqq' * `2' `if'
> 	local k = `k' + 1
>   }
>   local k=2
>   while `k' <= `x' {
> 	local pless1 = -1
> 	local p=3
> 	while "``p''" ~= "" {
> 		local pless1 = `p' - 1
> 		tempvar y`k'var`pless1'q
> 		ge `y`k'var`pless1'q' = `y`k'iqq' * ``p'' `if'
> 		local p = `p'+1
> 	}
> 	local k = `k' + 1
>   }                                /* separate loops so keep order of 
> vars */
>   local k=2
>   while `k' <= `x' {
> 	tempvar y`k'scscq
> 	ge `y`k'scscq' = `y`k'iqq' * `scoreqq' * `scoreqq' `if'
> 	local k = `k'+1
>   }
> 
>  }
> 
> 
> local yxiqqs=""
> if `onecut' ~= 1 { 
> 	local yxiqqs=" `y2iqq'-`y`x'iqq' " 
> }
> 
> 
> 
> if "`heteroscedasticity'" ~= "" {
> 	quietly regress `regdepqq' `evar1qq'-`evar`m'qq' `hetvar' `yxiqqs' 
> `if' [`weight' `exp'], noconstant
> 	if e(N) ~= `obs' { display "ERROR " e(N) "observations, when should 
> be " `obs' }
> 	display in text "Heteroscedasticity w.r.t. `namevar'" _col(48) "{c 
> |}" %11.7f as result e(r2)*e(N) %18.7f chi2tail(1,e(r2)*e(N)) 
> 
> }
> 
> display as text "{hline 47}" _col(48) "{c BT}" "{hline 31}"
> 
> end

Main question is what is `2' when the program 
crashes. 

Insert -noi mac li- just before that line. 

Nick 
n.j.cox@durham.ac.uk 

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   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   |   What's new   |   Site index