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: Re: [question on -gammafit- and -pgamma-]
From
"Kieran McCaul" <[email protected]>
To
<[email protected]>
Subject
RE: st: Re: [question on -gammafit- and -pgamma-]
Date
Mon, 7 Mar 2011 08:23:42 +0800
...
You need to use the variance/covariance matrix, e(V), to calculate the standard errors and from these the upper and lower confidence intervals.
matrix V = e(V)
matrix se = vecdiag(cholesky(diag(vecdiag(V))))
the matrix se will now contain the standard errors.
If you are running simulations, it would probably be more efficient to save these in you results matrix and calculate the upper and lower limits when all the simulations have run.
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Peter Maclean
Sent: Monday, 7 March 2011 4:57 AM
To: [email protected]
Subject: Re: st: Re: [question on -gammafit- and -pgamma-]
When you use -level option you get specific lower and upper limits of the
coefficients. However, the
e(b) matrix saves only the coefficients. I need confidence intervals for
different levels of significance and save the results in a matrix for simulation
purposes. How do you actually do that?
Peter Maclean
Department of Economics
UDSM
----- Original Message ----
From: Nick Cox <[email protected]>
To: [email protected]
Sent: Sun, March 6, 2011 2:44:08 AM
Subject: Re: st: Re: [question on -gammafit- and -pgamma-]
You need [] not () before the equals sign in commands like
matrix results(`i',2)=e(beta)
i.e.
matrix results[`i',2]=e(beta)
This was explicit in my first email and is explicit in the help for -matrix-.
You have to get used to copying syntax exactly, character by
character, until you have learned it!
Nick
On Sun, Mar 6, 2011 at 5:36 AM, Peter Maclean <[email protected]> wrote:
> I made the changes but there are still some errors.
>
> for:
>
> matrix results=J(10,3,.)
> egen group = group(n)
> su group, meanonly
> forval i = 1/`r(max)' {
> gammafit y if group == `i'
> results(`i',1)=e(alpha)
> results(`i',2)=e(beta)
> results(`i',3)=e(alpha)*e(beta)
> }
> gives:
> unrecognized command: results
> r(199);
>
>
> For:
>
> matrix results=J(10,3,.)
> egen group = group(n)
> su group, meanonly
> forval i = 1/`r(max)' {
> gammafit y if group == `i'
> matrix results(`i',1)=e(alpha)
> matrix results(`i',2)=e(beta)
> matrix results(`i',3)=e(alpha)*e(beta)
> }
>
> gives:
>
> invalid syntax
> r(198);
>
>
>
> ----- Original Message ----
> From: Kieran McCaul <[email protected]>
>
> (1) get rid of the comma after the gammafit and put the -if- on the same line.
> gammafit y if group == `i'
> (2) the matrix "results" is not the same as the matrix "Results". Pick one
>name
> or the other.
> (3) You need to preface the matrix assignments with the command -matrix-.
>
> [mailto:[email protected]] On Behalf Of Peter Maclean
>
> I tried use the following commnds:
>
> matrix results=J(10,3,.)
> egen group = group(n)
> su group, meanonly
> forval i = 1/`r(max)' {
> gammafit y,
> if group == `i'
> Results(`i',1)=e(alpha)
> Results(`i',2)=e(beta)
> results(`i',3)=e(alpha)*e(beta)
> }
>
> I am still getting the following error
>
> { required
> r(100); and it the results is for all observations.
> ----- Original Message ----
> From: Nick Cox <[email protected]>
>
> Start with
>
> -help foreach-
>
> -help forval-
>
> If necessary, continue with
>
> SJ-2-2 pr0005 . . . . . . Speaking Stata: How to face lists with fortitude
> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox
> Q2/02 SJ 2(2):202--222 (no commands)
> demonstrates the usefulness of for, foreach, forvalues, and
> local macros for interactive (non programming) tasks
>
> FAQ . . . . . . . . . . Making foreach go through all values of a variable
> . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . N. J. Cox
> 8/05 Is there a way to tell Stata to try all values of a
> particular variable in a foreach statement without
> specifying them?
> http://www.stata.com/support/faqs/data/foreach.html
>
> On Sat, Mar 5, 2011 at 10:25 PM, Peter Maclean <[email protected]> wrote:
>> Thanks Nick.
>> My question was actually setting up a loop over a group and save the results.
>> The number of group (n) is 600.
>> Hope you can help on that.
>>
>> ----- Original Message ----
>> From: Nick Cox <[email protected]>
>>
>> It is always helpful to specify a subject for your email.
>>
>> This question refers to -gammafit- and -pgamma- from SSC, which are
>> user-written programs.
>> Statalist etiquette is to explain where user-written programs referred
>> to come from.
>>
>> Peter quotes the syntax
>>
>> by n:gammafit y, level(95)
>>
>> which -gammafit- supports. However, as is standard with -by:- support,
>> this syntax is of limited use for _saving_ results, as after the
>> first, each invocation of -gammafit- stomps over the previous set of
>> saved results, so although parameter estimates are displayed in turn,
>> only the last such set is present in memory once all are done.
>>
>> Peter correctly reports that -pgamma- does not support the -by()-
>> option (nor does it support the -by:- prefix).
>>
>> I am not aware that Stata supports doubly subscripted variables.
>> Perhaps Peter means a Stata or Mata matrix.
>>
>> To get results for different groups and put them together, Peter has
>> to arrange that himself. But this code shows that the steps are
>> simple.
>>
>> sysuse auto, clear
>> matrix results = J(2,2,.)
>> gammafit mpg if foreign
>> matrix results[1,1] = e(alpha)
>> matrix results[1,2] = e(beta)
>> pgamma mpg if foreign, gen(tp1 ep1)
>> gammafit mpg if !foreign
>> matrix results[2,1] = e(alpha)
>> matrix results[2,2] = e(beta)
>> pgamma mpg if !foreign, gen(tp2 ep2)
>> matrix rownames results = Foreign Domestic
>> matrix colnames results = alpha beta
>> matrix li results
>> scatter tp1 ep1 || scatter tp2 ep2 , legend(order(1 "Foreign" 2 "Domestic"))
>>
>> For a group variable with many more than 2 classes, it would be better
>> to set up a loop over the groups.
>>
>> The help for -gammafit- includes a link to the help for -maximize-,
>> which explains how to set initial values.
>>
>> Nick
>>
>> On Sat, Mar 5, 2011 at 4:47 PM, Peter Maclean <[email protected]> wrote:
>>
>>> I am new is Stata modelling.
>>> I am running the following model:
>>>
>>> by n:gammafit y, level(95)
>>> pgamma y, gen(g_p e_p)
>>>
>>> where n is a group variable.
>>> I would like to save the estimated parameters by gammafit
>>>(alpha,beta,alpha+beta
>>> and lower and upper limit of both alpha and beta) in a variable
> 'result(n,j).'
>>>
>>>
>>> Also, I would like pgamma to estimate the probabilities (g_p and e_p) by
>>> variable n.
>>> The pgamma module does not accept the 'by' option. In addition, is there a
> way
>>> to give starting values for the gammafit module?
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/
*
* For searches and help try:
* http://www.stata.com/help.cgi?search
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/