Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


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

Re: st: Problems with:"drawnorm "$varlist"_1, mean(b1) cov(V1)


From   Jeph Herrin <stata@spandrel.net>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Problems with:"drawnorm "$varlist"_1, mean(b1) cov(V1)
Date   Thu, 09 Sep 2010 12:18:36 -0400

This might work for you

 global varlist "x_ y_ z_"
 forvalues c=1/5 {
	global newvarlist=subinstr("$varlist","_","_`c'",.)
        drawnorm $newvarlist, mean(b`c') cov(V`c')
 }

hth,
Jeph

On 9/9/2010 10:52 AM, Daniele Pacifico wrote:
Dear Statalist,

I have a problem with the following loop:

global varlist "x y z"
forvalues c=1/5{
drawnorm "$varlist"_`c', mean(b`c') cov(V`c')
}

Where b`c' is a 1x5 vector and V`c' is a 5x5 matrix..

With the previous loop I would like to create these new set of variables:
x_1, y_1, z_1 with mean b_1 and var-cov V_1;
x_2, y_2, z_2 with mean b_2 and var-cov V_2;
etc..


In other words, I would like to create 3x5 new variables using the same name
of the tree main variables (x,y,z) but adding  _`c'  at the end of each of
them... Of course, I can always write:

forvalues c=1/5{

drawnorm x_`c' y_`c' z_`c' , mean(b`c') cov(V`c')
}
and get what I want.. However, I need to find a way that allows me to change
automatically the number and the name of the variables in varlist..
Any advise about the right way of constructing this type of loop?

Thanks in advance,
Daniele Pacifico





*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index