Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Nick Cox <njcoxstata@gmail.com> |
To | "statalist@hsphsun2.harvard.edu" <statalist@hsphsun2.harvard.edu> |
Subject | Re: st: creating a table of own design |
Date | Mon, 9 Dec 2013 09:05:30 +0000 |
You seem to be in some doubt about mat A = ("a"\"b") but that will produce an error message of -type mismatch- and the reason in turn is simple: Stata matrices are for numbers only and may not include strings. Here's how Stata introduces matrices at [U] 14.1.1 "To Stata, a matrix is a named entity containing an r x c (0 < r <= matsize, 0 < c <= matsize) rectangular array of double-precision numbers (including missing values) that is bordered by a row and a column of names." Learning Stata programming is tricky, but made less tricky by approaching it the right way. Here's my RST method for learning Stata programming. Read the documentation. There's really no alternative. [U] contained the first and in many ways still one of the best treatments. (Your problem, as above, is explained directly in [U].) Kit Baum's book http://www.stata.com/bookstore/stata-programming-introduction/ is also well paced and well explained. Slow but sure. Learners often slap down several lines of code and then say, "Why isn't my program working?" Focus on one line at a time and think about getting each one right. If you are learning, ten lines of code can be very long, but Stata will stop at the first error, regardless of whether later code is good. Test, test, test. Stata's debugging environment is not spectacular, but it's more than enough to help progress. -set trace on- often helps. Most of the tests one needs are a matter of looking at the data, macros, scalars, matrices, to see what they are (or whether Stata can see them). To build up a table as you intend, I recommend simply using -display- to produce a line at a time.http://www.stata-journal.com/article.html?article=pr0053 may help. On "local variable", see http://www.stata.com/statalist/archive/2008-08/msg01258.html Nick njcoxstata@gmail.com On 9 December 2013 05:00, Jason Park <loooooo.j8311@gmail.com> wrote: > Not being perfectly familiar with the Stata's programing language, I'm > struggling doing some easy stuff that could easily be done in other > languages. Please forgive me if I'm asking about too basic a thing > that most of you already know. > > I got to the point where I can generate some figures that I need in a > do file, and now I want to tabulate them. > Suppose the local variables those figures are saved in are a and b. > My intention is to present a table looking like below (not necessarily > with the broken lines though or the header): > z-stat > ------------------ > a 1.2345 > b 1.1234 > ------------------ > > So far, I tried to create a matrix containing strings, A and B, and > another matrix with the figures, and join side by side, which didn't > work anyhow. > The faulty code I wrote is: > mat A = ("a"\"b") > mat B = (`a'\`b') > mat C = A,B > mat list C > It seems that the first line is returning an error. Neither does A = > ("a"\"b") work. > > Could someone give me some tips? It will be greatly appreciated if > someone suggests a better way of tabulation, but if not, it will also > be equally appreciated if someone helps me get my code to work. * * 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/