First, -univar- is doing nothing
useful here that -summarize- cannot
do directly, so cut out the middle
program.
Second, there is a lot of file i/o
here that can be cut down. The
writing to file can be done just
once, outside the loop. [Code
not shown.]
On your main point, the line
matrix rownames statdes = `var'
can be replaced roughly like this:
local label : variable label `var'
capture matrix rownames statdes = `label'
if _rc {
matrix rownames statdes = `var'
}
but a good way to go is build up your
matrix vector by vector, in addition
to all this.
capture erase statdes.txt
foreach var of varlist size1 lev2 {
qui su `var'
loc N = r(N)
loc mean = r(mean)
loc sd = r(sd)
sktest `var'
loc chi2= r(chi2)
loc adj_chi2=r(P_chi2)
matrix statdes = (`N', `mean', `sd', `chi2', `adj_chi2')
matrix rownames statdes = `var'
matrix colnames statdes = N mean sd chi2 Prob(chi2)
mat2txt, matrix(statdes) saving(statdes) append
Nick
[email protected]
Herve STOLOWY
> I apply the following code to obtain a matrix with descriptive
> statistics and transform it in a .txt (then Excel) file.
>
> capture erase statdes.txt
> foreach var of varlist size1 lev2 {
> univar `var'
> loc N = r(N)
> loc mean = r(mean)
> loc sd = r(sd)
> sktest `var'
> loc chi2= r(chi2)
> loc adj_chi2=r(P_chi2)
> matrix statdes = (`N', `mean', `sd', `chi2', `adj_chi2')
> matrix rownames statdes = `var'
> matrix colnames statdes = N mean sd chi2 Prob(chi2)
> mat2txt, matrix(statdes) saving(statdes) append
>
> It works.
>
> In the rownames, I get the var names (size1, lev2). However, I would
> prefer to get the label names (Size and Leverage). Is there a
> way to do
> this?
>
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/