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

st: erros when calculating adaptive values


From   Yibing Wang <[email protected]>
To   [email protected]
Subject   st: erros when calculating adaptive values
Date   Thu, 22 May 2003 09:07:32 -0700 (PDT)

Dear Statalisters,

I am using the following program to estimate a
bivariate conditional density:

program define bivkern
  version 5.0
* This programs estimates a bivariate kernel density
using a fixed bandwidth
set matsize 100
capture confirm existence `1'
capture confirm existence `2'
capture confirm number `3' 
capture confirm number `4'
capture confirm number `5'
 
tempvar count1 count2 xxo yyo zzx zzy kkzx kkzy 
tempvar ssumxy kzxkzy h1 h2 nuobs fxy

quietly {
gen `fxy'=0
gen `nuobs'=`5'
gen `h1'=`3'
gen `h2'=`4'
gen `count1'=1
gen `count2'=1
gen `xxo'=0
gen `yyo'=0
gen `ssumxy'=0
gen `kzxkzy'=0
gen `zzx'=0
gen `zzy'=0
gen `kkzx'=0
gen `kkzy'=0

noisily display "CALULCATING FIRST STAGE ESTIMATES"


while `count1'<=`5' {
        noi di "Calculating fk(x) number = " `count1'
`count1'
    replace `xxo'=`1'[`count1']
    replace `zzx'=(`xxo'-`1')/`h1'
    replace `yyo'=`2'[`count1']
    replace `zzy'=(`yyo'-`2')/`h2'
    
replace `kkzx'=(1/(sqrt(2*_pi)))*exp(-.5*`zzx'^2) 
replace `kkzy'=(1/(sqrt(2*_pi)))*exp(-.5*`zzy'^2) 

replace `kzxkzy'=`kkzx'*`kkzy'
replace `ssumxy'=sum(`kzxkzy')
  
 
replace `fxy'=(1/(`nuobs'*`h1'*`h2'))*`ssumxy'[`5'] if
_n==`count1'
replace `kkzx'=0
replace `kkzy'=0
replace `kzxkzy'=0
    
replace `count1'=`count1'+1 }

 
*Calculating local weights
tempvar lnfyx lnfg fg winfac

gen `lnfyx' = log(`fxy')
summ `lnfyx'
gen `lnfg' =_result(3)
gen `fg' = exp(`lnfg')
gen `winfac'=sqrt(`fg'/`fxy')

tempvar c1 c2 xo yo zx zy kzx kzy kxy sumxy mx my m1y 
tempvar m1x iy ix ry rx gzy kg sumxg sumx kzxx
 
gen `kzxx'=0
gen `c1'=1
gen `c2'=1
gen `xo'=0
gen `yo'=0
gen `sumxy'=0
gen `zx'=0
gen `zy'=0
gen `kzx'=0
gen `kzy'=0
gen `kxy'=0
gen `gzy'=0
gen `kg'=0
gen `sumxg'=0
gen `sumx'=0

matrix A=J(100,100,0)
matrix S=J(100,100,0)
matrix C=J(100,100,0)
matrix D=J(100,1,0)


* Generating 50 equally spaced x and y points at which
to evaluate the density

sum `1'
gen `m1x'=_result(5)-`h1'
gen `rx'= _result(6)- _result(5)+2*`h1'
gen `ix' = `rx'/50
gen `mx'=sum(`ix')+`m1x' +`ix'/2

sum `2'
gen `m1y' =_result(5)-`h2'
gen `ry'= _result(6)-_result(5)+2*`h2'
gen `iy' = `ry'/50
gen `my'=sum(`iy')+`m1y' +`iy'/2


noisily display "CALCULATING ADAPTIVE VALUES"
  
while `c1'<=100 {
  replace `c2'=1
   while `c2'<=100 {
        noisily display "Calculating fk(x) number = "
`c1' `c2'
    replace `xo'=`mx'[`c1']
    replace `zx'=(`xo'-`1')/(`h1'*`winfac')
    replace `yo'=`my'[`c2']
    replace `zy'=(`yo'-`2')/(`h2'*`winfac')
    
replace `kzxx'=(1/(sqrt(2*_pi)))*exp(-.5*`zx'^2) 
replace `kzx'=(1/(sqrt(2*_pi)))*exp(-.5*`zx'^2) 
replace `kzy'=(1/(sqrt(2*_pi)))*exp(-.5*`zy'^2) 
replace `gzy'=normprob(`zy') 
replace `kg'=`kzx'*`gzy'
replace `kxy'=`kzx'*`kzy'
replace `sumxy'=sum(`kxy'/(`winfac'^2))
replace `sumxg'=sum(`kg'/`winfac')
replace `sumx'=sum(`kzxx'/`winfac')

local i = `c1'
local j = `c2'

matrix A[`i',`j']=(1/(`nuobs'*`h1'*`h2'))*`sumxy'[`5']
matrix S[`i',`j']=`sumxg'[`5']/`sumx'[`5']
matrix D[`i',1]=(1/(`nuobs'*`h1'))*`sumx'[`5']
matrix
C[`i',`j']=((1/(`nuobs'*`h1'*`h2'))*`sumxy'[`5']) /
((1/(`nuobs'*`h1'))*`sumx'[`5'])
replace `kzx'=0
replace `kzy'=0
replace `kxy'=0
replace `gzy'=0
replace `kg'=0
replace `kzxx'=0
replace `c2'=`c2'+1 }
replace `c1'=`c1'+1 }
 
noisily display "DONE. THANK FOR YOUR PATIENCE"

  }
.....
(omitted)
end

when I pass the data to the program by typing:
bivkern y1950 y2000 band1 band2 size
(y1950 y2000 band1 band2 size are variables in my
data)

execution goes well until calculating the adaptive
values:

(omitted)
....
Calculating fk(x) number = 6060
CALCULATING ADAPTIVE VALUES
Calculating fk(x) number = 11
__00000C not found
r(111);

It seems that variable names are missing when
calculating adaptive values, but I have already
specified all the varibales in tempvar, so what's
going wrong here? Any help or advice is appreciated.

Thanks,

Eric Wang
University of Calgary

__________________________________
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
http://search.yahoo.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