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: scalar do not allow -if-


From   Scott Merryman <[email protected]>
To   [email protected]
Subject   Re: st: scalar do not allow -if-
Date   Wed, 17 Nov 2010 10:15:06 -0600

Something like this?


forv i = 1/3 {
	scalar w`i' = ceil(10*runiform())
}


if scalar(w1) > scalar(w2) & scalar(w1) > scalar(w3) {
	scalar hig = 1
}
else if scalar(w2) > scalar(w1) & scalar(w2) > scalar(w3) {
	scalar hig = 2
}
else if scalar(w3) > scalar(w1) & scalar(w3) > scalar(w2) {
		scalar hig = 3
}
else {
	scalar hig = 0
}
scalar list _all


Scott


On Wed, Nov 17, 2010 at 9:27 AM, Tomas Lind <[email protected]> wrote:
> Dear Statalisters,
>
> In a small simulation I generate data and analyze them with 3 regression methods. In the bottom of the loop I save (among other things)
>
> scalar b2   = exp(_b[x])        // beta
>
> and then put the -scalar- values into a variable in a dataset where I collect the results from the 1000 simulated datasets. For example
>
> quietly replace b2=scalar(b1) in `i'
>
>
> That works fine. Now I want to calculate "hig" (in the bottom of the loop) and save it in the dataset with aggregated data (where w1, w2, w3 are -scalars-).
>
> scalar hig = 1  if (w1 > w2) & (w1 > w3)
> scalar hig = 2  if (w2 > w1) & (w2 > w3)
> scalar hig = 3  if (w3 > w1) & (w3 > w1)
>
> However, -if- is not allowed in combination with  -scalar-.
>
> Anyone know a better solution for this.
>
> /Tomas
>
> *
> *   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index