Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: does the


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: does the
Date   Thu, 7 Mar 2013 10:47:08 +0000

I don't understand your guess, nor the comment that -sum- does not work here.

But there is no need to guess: use

set trace on
set traced 1

so see where your program fails.

This is illegal:

       forvalues i=1(1)n {

Stata won't evaluate your scalar -n- is that context. This should work

      forval i = 1/`=n' {

There may be other problems too.

Nick

On Thu, Mar 7, 2013 at 5:16 AM, Wu Zhang <[email protected]> wrote:
> Hi folks,
>
>    I encounter this error message : invalid syntax r(198);
> My guess is that 'tabstat' with option 'save' does not work since the matrix xstat is null, but I cannot fix it; any thoughts? thanks!
>
>
>   My code is as follows:
>
> program ape_total, rclass
>       version 8
>       syntax varlist(numeric)
>       gettoken y x : varlist  /*nice way to split y and x! from Maarten*/
>
>
>
>       tabstat `x', statistics( mean p25 p50 p75 p95 ) save   /*'sum' does not work here!*/
>
>       mat xstat=r(StatTotal)
>       scalar n=rowsof(xstat)
>       scalar m=colsof(xstat)
>       regress `varlist'
>       predict ehat, residual
>       mat paraest=e(b)
>
>
>
>       forvalues i=1(1)n {
>            mat meanvalue=(xstat[i, 1...],1)*paraest'
>            scalar meanvalues=meanvalue[1,1]
>         forvalues j=1(1)m{
>            scalar alpha`j'=paraest[1,j]
>            gen apet`i'`j'=alpha`j'*exp(meanvalues+ehat)/(1+exp(meanvalues+ehat))^2
>            sum apet`i'`j'
>            return scalar ape`i'`j'=r(mean)
>
>
>       }
>       }
>
>       drop apet* ehat
>
> end
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index