[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
"Herve STOLOWY" <[email protected]> |

To |
<[email protected]> |

Subject |
Re: st: RE: Label instead of var names in a matrix |

Date |
Thu, 16 Dec 2004 20:41:35 +0100 |

Dear Nick: First of all, thank you again for your help. I am a real beginner with programming and matrices. So, I do understand that my coding is not "clean" at all. I tried to implement what you suggest. It partly works, in the sense that, treating three variables, I get the label for the first two but not for the last one (where I get the var name). I checked that the label is available in the data and there is no doubt. Here is my coding: capture erase statdes.txt foreach var of varlist size1 lev2 sales_int3 { qui summarize `var' loc N = r(N) loc mean = r(mean) loc sd = r(sd) sktest `var' loc adj_chi2= r(chi2) loc prob_chi2=r(P_chi2) matrix statdes = (`N', `mean', `sd', `adj_chi2', `prob_chi2') local label : variable label `var' capture matrix rownames statdes = `label' if _rc{ matrix rownames statdes = `var' } matrix colnames statdes = N mean sd chi2 Prob(chi2) mat2txt, matrix(statdes) saving(statdes) append } (I did not follow all your suggestions because I did not understand all of them. I replaced -univar- by -summarize- and inserted the few lines concerning the row names). If what I am asking exceeds the scope of the StataList, please don't hesitate to tell me because I do feel that I am taking a lot of your time. Best regards Herv� *********************************************************** HEC Paris D�partement Comptabilit� Contr�le de gestion / Dept of Accounting and Management Control 1, rue de la Liberation 78351 - Jouy-en-Josas France Tel: +33 1 39 67 94 42 Fax: +33 1 39 67 70 86 [email protected] http://campus.hec.fr/profs/stolowy/perso/home.htm >>> [email protected] 12/15/04 10:48 PM >>> 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/ * * 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/

- Prev by Date:
**Re: st: VIF different between -vif- and -collin-** - Next by Date:
**Re: st: Refresh an Ado file when is programing** - Previous by thread:
**st: RE: Label instead of var names in a matrix** - Next by thread:
**RE: st: RE: Label instead of var names in a matrix** - Index(es):

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