Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

st: wrap string observation values with double quotation


From   tashi lama <ltashi32@hotmail.com>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: wrap string observation values with double quotation
Date   Tue, 24 Jul 2012 18:12:25 +0000

Hello all, 

date                title                  hits
01jan2011           Expect strong dec       4
02jan2011           Bearish stock           3
03jan2011           Long summer             5

The idea is to be able to use ttext as follows 

tsline hits, ttext(01jan2011 "Expect strong dec" 02jan2011 "Bearish stock" 03jan2011 "Long summer")

I approached, 

tostring date title, replace 
gen b=date+" "+title 
levelsof b, local(n)
tsline hits, tline(`n')  => stata is unhappy and returns invalid point, because titles are not inside quotation mark

I think I could have this in 2 ways...

1. use replace title to have although I don't know how to( I hope someone will give me a hint)

title 
"Expect string dec"
"Bearish stock"
"Long summer"

2. use one of the string functions like 

levels n, local(n)
di `n'
01jan2011 Expect strong dec 02jan2011 Bearish stock 03jan2011 Long summer 
use subinstr or regexm to generate 
01jan2011 "Expect strong dec" 02jan2011 "Bearish stock" 03jan2011 "Long summer"

subinstr sounds like a perfect fit and I did 
subinstr("`n'","[a-zA-Z]",""[a-zA-Z]"",.)   =>no luck 

Could someone give me an idea how to do it in either ways... 

Thanx, 
Tashi 

  		 	   		  
*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index