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 <[email protected]>
To   "[email protected]" <[email protected]>
Subject   Re: st: Variable values as labels in matrix output???
Date   Thu, 27 Feb 2014 13:56:34 -0500

Rebecca,
copy the file
http://radyakin.org/stata/tab2file/tab2file.ado
to a folder somewhere along the adopath where Stata will find it, then
you can do
do http://radyakin.org/stata/tab2file/test.do

The output is:
http://radyakin.org/stata/tab2file/nlsw88_occup.txt
http://radyakin.org/stata/tab2file/nlsw88_occup.png

Hope this helps.
Sergiy Radyakin

On Thu, Feb 27, 2014 at 4:13 AM, Kanter, Rebecca <[email protected]> wrote:
> Dear Sergiy and others,
> Thank you for your help.
> I want to be able to write the whole first three columns of the chi-2 table below to a text file.
> I can get the 2nd and 3rd columns but I am still having trouble with the 1st column.
> I understand the levelsof var command but then I am not sure what to do next to write those number values to rows of text that would go here:
>  file write `holding' *WANT number of calls here* _tab (cell[1,1]) _tab (cell[1,2])  _n
>
> Where and how do I write ":word # in ..." to obtain each level (rowname)?
>
> Any further help you can provide would be much appreciated.
>
> Many thanks and best,
> Rebecca
> _____
> 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 <[email protected]> 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