Statalist


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

st: RE: a possible - foreach - question?


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: RE: a possible - foreach - question?
Date   Tue, 14 Oct 2008 11:04:09 +0200

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


HTH
Martin


-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Carlo Lazzaro
Sent: Tuesday, October 14, 2008 10:50 AM
To: [email protected]
Subject: st: a possible - foreach - question?

Dear Statalisters,
I have three variables (a; b; C with 10,000 observations each) in long
format.
For each value of a I would like to obtain the following one:

(a1 * b1) - c1
.
.
.
.
(a1*b10,000)-c10,000;

Repeat the above reported would-be 10,000 times (i.e., from a1 to a10,000)

Create a new variable d in which the mean of each one of the 10,000
iterations are stored and can be displayed.

I suppose there's way of doing this with Stata 9.2/SE, but I cannot figure
out the proper syntax.

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/



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