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

st: tempvar


From   "Anna-Lisa Pierre" <[email protected]>
To   [email protected]
Subject   st: tempvar
Date   Fri, 07 Jun 2002 14:30:22 +0000

Hi

I am trying to use the 'tempvar' command so that I do not have to drop variables at the end. However, I am having problems using this within loops. Are 'tempvar' and 'tempname' not supposed to be used within loops? The part of my programme that is giving trouble is as follows:
Any insights will be gratefully appreciated.

tempvar wj_1 phiwj_1 PHIwj_1 diffqq2;
while `j' <= `depmax' { ;

local xless1 = `x'-1 ;

if `j' < `depmax' { ;
ge `diffqq2' = ( 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 `diffqq2' = normprob(`scor_uqq'-_b[_cut`xless1']) - normprob(`scor_nqq'-_b[_cut`xless1']) if `1'~=. ;
} ;


su `diffqq2' `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' ;


tempvar y`x'iqq y`xless1'iqq;
if `j'~=`depmax' { ;
capture drop `y`x'iqq' ;
if _rc == 0 { local dropvar="`dropvar' `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' ;
} ;


#delimit cr

_________________________________________________________________
Join the world�s largest e-mail service with MSN Hotmail. http://www.hotmail.com

*
* 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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index