Statalist


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

R: st: RE: how to work around -levelsof- limits with Stata 9.2/SE?


From   "Carlo Lazzaro" <[email protected]>
To   <[email protected]>
Subject   R: st: RE: how to work around -levelsof- limits with Stata 9.2/SE?
Date   Tue, 14 Oct 2008 14:51:42 +0200

Dear Johannes,
Thanks a lot for your kind reply. Your hint works fine and does not cause
any problem with Stata.

I will compare the results obtained following the different approaches that
you, Ben and Martin were kind enough to provide me with.

Thanks a lot again and Kind Regards,

Carlo


-----Messaggio originale-----
Da: [email protected]
[mailto:[email protected]] Per conto di Johannes Geyer
Inviato: martedì 14 ottobre 2008 14.28
A: [email protected]
Oggetto: Re: st: RE: how to work around -levelsof- limits with Stata 9.2/SE?

Maybe I am wrong, but wouldn't it be easier, if you are interested in 
those mean values, to do the following: 

let x be an index of your observations

MEAN_ax = (ax   * b1 - c1 + ax * b2 - c2 + ... ax * bN - cN) / N
MEAN_ax =  [ax   * (b1+b2+b3+...+bN)   -   c1+c2+c3+...cN)] / N

That reduces to, borrowing from Martin's code and adding some lines - the 
following:

***************
sysuse auto, clear

*get the levels of mpg (a in your xmpl)
levelsof mpg, loc(levels)

*loop through them, create new vars along the way
*price takes place of b in your code, headroom is c
foreach lev of loc levels{
g result`lev'=`lev'*price- headroom
}

*get the means from -summarize-
su result*

/* new code */

egen f = total(price)
egen g = total(headroom)
egen fg = count(f)
gen testresult = (mpg*f-g)/fg
tab testresult
*************
- of course, that could be written more elegant...

Best regards,

Johannes


----------------------
Johannes Geyer
Deutsches Institut für Wirtschaftsforschung (DIW Berlin)
German Institute for Economic Research 
Department of Public Economics
DIW Berlin
Mohrenstraße 58
10117 Berlin
Tel: +49-30-89789-258

[email protected] schrieb am 14/10/2008 13:49:38:

> I think it should be
> 
>  levelsof   ICER_round, loc(levels)
>  foreach lev of local levels {
>      generate result`lev' = `lev' * Delta_Q - Delta_C
>   }
> 
> However, are you really sure you want to generate 10000 variables?
> 
> Furthermore, should -levelsof- hits Stata's limits you could type
> 
>  mata: st_local("levels",
> mm_invtokens(strofreal(uniqrows(st_data(.,"ICER_round"))')))
> 
> assuming that ICER_round is a numeric variable (-mormata- required,
> type -ssc describe moremata-).
> 
> ben
> 
> On Tue, Oct 14, 2008 at 1:24 PM, Martin Weiss <[email protected]> 
wrote:
> > "levelsof may hit the limits imposed by your Stata.  However, it is
> > typically used when the number of distinct values of varname is 
modest."
> > (from -h levelsof-). I should have anticipated this problem. Are the 
levels
> > of your "a" in any way regularly spaced (to enable application of
> > -forvalues-)?
> >
> >
> > HTH
> > Martin
> >
> > -----Original Message-----
> > From: [email protected]
> > [mailto:[email protected]] On Behalf Of Carlo 
Lazzaro
> > Sent: Tuesday, October 14, 2008 12:44 PM
> > To: [email protected]
> > Subject: st: how to work around -levelsof- limits with Stata 9.2/SE?
> >
> >
> > Dear Statalisters,
> > I have performed successfully Martin's helpful syntax using -levelsof- 
on a
> > sample of 20 distinct values for var a.
> > However, when I tried to repeat the loop for the total 10,000 levels 
of var
> > a I got an error message(admittedly, the recommended limit for 
-levelsof- is
> > a modest number of distinct values for varlist, so I cannot complain 
about
> > this useful ado.file). Is there any way to work this around?
> >
> > Please find below the command lines I typed along with the error 
message I
> > got at the end of the sequence:
> >
> > . levelsof   ICER_round, loc(levels) *around 10,000 levels are still
> > reported after rounding to the nearest whole number
> > . foreach lev of local levels {
> >  2. g result`lev'=` ICER_round'* Delta_Q-  Delta_C
> >  3. }
> > invalid syntax
> > r(198);
> >
> > Thanks a lot for your kindness and for your time.
> >
> > Kind Regards,
> >
> > Carlo
> >
> *
> *   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/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index