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]

[no subject]



On Thu, May 5, 2011 at 5:44 PM, Woolton Lee <[email protected]> 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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index