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: AW: st: add column in -tabout- for symbols


From   Eric Booth <[email protected]>
To   "<[email protected]>" <[email protected]>
Subject   Re: AW: st: add column in -tabout- for symbols
Date   Mon, 13 Jun 2011 13:57:46 +0000

<>
Hi Marc:
That's a good point about spaces in v1 causing problems with split.  Your use of -regexm- is a good work around.
Another workaround might be to use -filefilter- to replace % and N with \tab% \tabN. The issue is that you'll need 
to be sure that none of your variable/value labels contain a capital N (or use a different symbol than N, like `=char(176)' 
and then go back at the end and loop across all your files and use -filefilter- to exchange that char for N).  Anyways, 
here's a similar approach using filefilter and the h2() h3() options to push the proper col. headings:
***********!
sysuse auto, clear
gen lengthc = length>200
lab def origin 1 "longer label with spaces", modify
lab def test 1 "one" 0 "zero", modify
lab val lengthc test
**
tabout foreign lengthc using test_tabout.txt, ///
style(tab) cells(row freq) ///
format(1 0) ///
clab(% N) layout(row) 	///
dpcomma replace h3(nil) ///
h2("`:var l for'" | | `:label test 0' | `:label test 1' | TOTAL)
type test_tabout.txt
**
 filefilter test_tabout.txt test_tabout_updated.txt , f(%) t(\t%) replace
 filefilter test_tabout_updated.txt test_tabout.txt , f(N) t(\tN) replace
type test_tabout.txt
***********!
- Eric
__
Eric A. Booth
Public Policy Research Institute
Texas A&M University
[email protected]


On Jun 13, 2011, at 8:36 AM, Kaulisch, Marc wrote:

> Eric,
> 
> Thanks a lot for your suggestion and apologies for my inappropriate
> change in the second table.
> 
> In my concrete example I have several spaces in v1 and so I need a
> different approach, but the following does the trick for me:
> preserve
> insheet using test_tabout.txt, nonames clear
> gen v11 = ""
> replace v11 = "N" if v1 == "N"
> replace v11 = "%" if regexm(v1, "%")
> replace v1 =  subinstr(v1, " %", "", 1)
> replace v1 = subinstr(v1, "N", "", 1) if v11 == "N"
> order v1 v11
> 
> outsheet using "test_tabout_updated.txt", ///
> 	replace nonames noquote
> restore 
> 
> Thanks again, (and if someone does know a better solution for -tabout- I
> would happy to integrate that ;-) )
> 
> Marc
> 
> *
> *   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