Yibing Wang
> I tried to use the Stata module kernreg1
> (KERNREG1: Stata module to compute kernel regression
> (Nadaraya-Watson estimator)
> http://ideas.repec.org/s/boc/bocode1.html)
>
> program define kernreg1
> version 3.1
>
> ...
> ...
>
> while `count'<=`np' {
> replace `xo'=`gridp'[`count']
> replace `z'=(`xo'-`xvar')/`h'
> if `kc'==1 {
> replace `kz'=0.5 if abs(`z')<=1 & `use'
> }
> else if `kc'==2 {
> replace `kz'=(1-abs(`z')) if abs(`z')<=1 &
> `use'
> }
> ...
> ...
>
> replace `sums'= sum(`kz')
> replace `sums2'= sum(`kzy')
> replace `fh'=(1/(`nuobs'*`h'))*`sums'[_N] if
> _n==`count'
> replace `rh'=(1/(`nuobs'*`h'))*`sums2'[_N] if
> _n==`count'
> replace `kz'=0
> replace `kzy'=0
> replace `count'=`count'+1
> }
>
> if `rh'==0 {
> replace `mh'=0
> }
> else {
> replace `mh'=`rh'/`fh'
> }
>
>
> My question is why `sums'[_N] is used instead of
> `sums' as we are trying to calculate fh from 1 to _N ?
>
> I have been trying to figure it out without success,
> can anybody give me some advice?
The variables `sums' and `sums2' contain cumulative
sums. Their last values contain the totals of each
variable.
Try it for yourself:
sysuse auto
gen summpg = sum(mpg)
list mpg summpg
di summpg[_N]
su mpg
di `r(sum)'
Nick
[email protected]
*
* 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/