Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Red Owl <rh.redowl@liu.edu> |
To | "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |
Subject | st: RE: Save results from flexible frequency table in 'matrix like' format |
Date | Wed, 17 Jul 2013 18:56:49 +0000 |
The example below may not be the most efficient way to create a vector of frequencies, but I believe it works. sysuse auto, clear levelsof mpg, local(mpglevels) local lvlsnum = wordcount("`mpglevels'") matrix FREQMAT = J(`lvlsnum',1,.) local lvlscount = 0 foreach lvl of local mpglevels { local lvlscount = `lvlscount' + 1 quietly tabstat mpg if mpg == `lvl', stat(count) save mat A = r(StatTotal) mat FREQMAT[`lvlscount',1] = A[1,1] } mat colnames FREQMAT = Frequency mat rownames FREQMAT = `mpglevels' matlist FREQMAT Red Owl (Yes, that's my real name) >> Dear members of Statalist, >> >> I have not been able to find appropriate way to save and export >> results from flexible frequency tables, so I kindly ask for your help. >> >> I would like to save for later use, a frequency table with multiple >> categorical variables, just like it appears in the result - like a >> matrix. Also, I need to keep the names of the variables to mark rows >> and columns. >> >> The dataset consists of many observations and mainly categorical >> variables (with some of them having tens of categories). >> >> I have tried the following ways to save the result after creating >> flexible frequency table: >> >> Copying and pasting the table into word is not good because the >> resulting table is very large; >> >> Replacing the original data set with the frequencies does not give me >> the matrix like format of the table; >> >> Collapsing the data after frequency also does not work well, because >> some of the variables are categorical and need to remain so, while >> frequencies are summed; >> >> The -matcell- option only worked with two-way frequency tables; >> >> -return- and -ereturn- did not contain any matrices. >> >> I would very much appreciate your suggestions and I thank you in advance. >> >> Regards, >> Milena Przheska * * 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/