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: forvalues, foreach and macro


From   Nick Cox <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: forvalues, foreach and macro
Date   Fri, 6 Dec 2013 19:12:01 +0000

Try

${toto`i'}

Stata is evaluating

$toto

then

`i'

which is not what you want.

Quelle horreur....

This is documented at [U] 18.3.10.
Nick
[email protected]


On 6 December 2013 19:02, BENSIDOUN Isabelle
<[email protected]> wrote:
> Hello,
>
> Is there anyone to help me ?
>
> I try to run the following code but it does not work
>
> forvalues i=2/ $c{
> mat drop _all
> global toto`i'= "cf`i'h* cf`i'f*"
> foreach VAR of varlist $toto`i' {
> bootvar `VAR'
> scalar `VAR'=`VAR'[1]
> scalar se_`VAR' = sigma
> scalar t_`VAR' =  `VAR'[1]/sigma
> scalar p_`VAR'=ttail($r, abs(t_`VAR'))
> }
> }
>
> In fact I don't understand why stata does not understand that
> foreach VAR of varlist $toto`i' means, when i=2, foreach VAR of varlist $toto2
> and instead understand foreach VAR of varlist 2 as mentionned in the following trace
>
>  forvalues i=2/ $c{
> = forvalues i=2/ 9{
> - mat drop _all
> - global toto`i'= "cf`i'h* cf`i'f*"
> = global toto2= "cf2h* cf2f*"
> - foreach VAR of varlist $toto`i' {
> = foreach VAR of varlist 2 {
> 2 invalid name
>   bootvar `VAR'
>   scalar `VAR'=`VAR'[1]
>   scalar se_`VAR' = sigma
>   scalar t_`VAR' = `VAR'[1]/sigma
>   scalar p_`VAR'=ttail($r, abs(t_`VAR'))
>   }
>
> Thank in advance for your suggestions.
>
> Isabelle
> ---------------------------------------------------------------------------------------------------------------------------IMPORTANT : Ce message et toutes les pièces jointes sont confidentiels et établis à l'intention exclusive de son ou ses destinataires. Si vous avez reçu ce message par erreur, merci d'en avertir immédiatement l'émetteur et de détruire le message. Toute modification, édition, utilisation ou diffusion non autorisée est interdite. L'émetteur décline toute responsabilité au titre de ce message s'il a été modifié, déformé, falsifié ou encore édité ou diffusé sans autorisation.
>
> *
> *   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/

*
*   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