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 on April 23, and its replacement, statalist.org is already up and running.


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

[no subject]



On Thu, May 5, 2011 at 5:44 PM, Woolton Lee <finished07@gmail.com> wrote:
> I have a program which creates descriptive statistics using tab1,
> summarize and other functions, stores the macros then posts them using
> postfile and creates tables that can be cut and pasted easily into a
> word document.
<snip>
> This loop creates the variables mn and sd and rounds the result of the
> numbers I want to two decimal places then uses summarize to store
> these values into macros.  I wonder if there is another more efficient
> way to do this?

Yes, use the extended macro function -: display-, like in the example
below:

*-------------- begin example -----------------------
sysuse auto, clear
ds , has(type numeric)
local vars2 `r(varlist)'

foreach v of local vars2 {
    sum `v'
    local m`v' : display %9.2f r(mean)
    local sd`v' : display %9.2f r(sd)
}

foreach v of local vars2 {
    di as txt "mean of `v' = " as result `m`v''
}
*-------------------- end example ----------------------

You can read more about extended macro functions by typing in
Stata -help extended_fcn- (I never remember the exact name, so
I always type -help macro- or -help local- and than click on the link
for extended macro functions).

Hope this helps,
Maarten

--------------------------
Maarten L. Buis
Institut fuer Soziologie
Universitaet Tuebingen
Wilhelmstrasse 36
72074 Tuebingen
Germany
*
*   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