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]

Re: st: Variable values as labels in matrix output???


From   Sergiy Radyakin <serjradyakin@gmail.com>
To   "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu>
Subject   Re: st: Variable values as labels in matrix output???
Date   Wed, 26 Feb 2014 18:38:27 -0500

Rebecca, if I understood the problem correctly, you can use:
 levelsof var, local(levs)
to obtain the levels of a var, and save them to local levs.
Then use ":word # in ..." to obtain each level (rowname).

Do you want to write just a few elements from the matcell-matrix? I
see a loop by different variables, but not by rows of matrix. This is
somewhat confusing. I mean fixing the indices in this line:
... _tab (cell[1,1]) _tab (cell[1,2])


Best, Sergiy

On Wed, Feb 26, 2014 at 5:51 PM, Kanter, Rebecca <rkanter@jhsph.edu> wrote:
> Dear Statalist,
>
> If I have the following chi2-table that I want to write into a text file-how do I store the values of the variable (calls) into the row names; is there a local command or something I can include??-so far I have this, but it is missing the row names..
> tempname holding
> file open `holding' using "xxx.txt", write replace
> foreach var of varlist calls {
>      local name : variable label `var'
>      tabulate `var' Genero if IDtag==1, chi2 matcell(cell)
>      local N = r(N)
>      local X = r(chi2)
>      local pvalue : display %-9.4f r(p)
>      file write `holding' ("`var'") _tab ("Males") _tab ("Females") _tab (`N') _tab ("`p'") _n
>      file write `holding' *WANT number of calls here* _tab (cell[1,1]) _tab (cell[1,2])  _n
> }
> file close `holding'
>
>            |        Genero
> calls | Masculino   Femenino |     Total
> -----------+----------------------+----------
>          0 |         2          0 |         2
>          1 |         4          3 |         7
>          2 |         2          6 |         8
>          3 |         2          2 |         4
>          4 |         4          2 |         6
>          5 |         5          4 |         9
>          6 |         0          6 |         6
>          7 |         7         12 |        19
>          8 |         8         21 |        29
>          9 |        16         20 |        36
>         10 |        19         22 |        41
>         11 |        19         26 |        45
>         12 |        59         45 |       104
> -----------+----------------------+----------
>      Total |       147        169 |       316
>
>
> ___________________________________________
> Rebecca M. Kanter, PhD
> Visiting Research Fellow with LCIRAH: www.lcirah.ac.uk
> London School of Hygiene and Tropical Medicine
> *I am 5 hours after US time* (Please, Mind the gap)
> Johns Hopkins Bloomberg School of Public Health
> Department of International Health
> Center for Human Nutrition
> http://rebeccafh.wix.com/rkanter
> *
> *   For searches and help try:
> *   http://www.stata.com/help.cgi?search
> *   http://www.stata.com/support/faqs/resources/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/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index