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: Store results from table command in matrix


From   Barbro Widerstedt <[email protected]>
To   [email protected]
Subject   Re: st: Store results from table command in matrix
Date   Wed, 23 Nov 2011 18:08:24 +0100

Thank you Kit and Nick; now I know that it's just not due my inferior
searching of the archive that I have failed to find this.

(Why I would want to do this? sometimes I want to repeat a command
that is not "byable" by a particular subset , e.g. year, and then use
that number for something else. If I forget to populate a matrix in
the loop, a table could be an alternative way to get to the data
without redoing the loop. My 'algorithmic mind' works this way; it may
not be optimal, but at least I understand what I am doing)

Thanks again
/Barbro



On Tue, Nov 22, 2011 at 5:02 PM, Nick Cox <[email protected]> wrote:
> I agree with Kit's emphasis and details.
>
> In addition, note that -collapse- can be used to produce a small
> dataset of means which can be exported elsewhere.
>
> Nick
>
> On Tue, Nov 22, 2011 at 3:52 PM, Christopher Baum <[email protected]> wrote:
>> <>
>> Barbro asks
>>
>> Is there something similar to tabstatmat or makematrix for the table command?
>>
>> I would like to use the results from a "table" command as a matrix.
>> -- example command
>>
>> .table var1 var2 , c(mean var3) concise
>>
>> does a simple solution to this problem exist?
>>
>> Please help - I do seem to have problems in phrasing the question in a
>> way that doesn't produce a huge number of irrelevant results
>>
>>
>>
>> No. As you can see from --return list--, the --table-- command does not save anything beyond the sample size.
>> Ian Watson's --tabout-- from SSC can be used to do this in a somewhat roundabout manner.
>>
>> sysuse auto
>> tabout mpg rep78 using junk.csv, c(mean price) sum replace f(1)
>> insheet using junk.csv,clear
>> destring v*, force replace
>>
>> This will create numeric variables. If you want them as a Stata matrix (why?) you can use mkmat. Note that values not appearing in the two-way table show up as missings, so you might want to mvencode them as zeros (or not).
>>
> *
> *   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/
>

*
*   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