Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

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

st: wrap string observation values with double quotation

From   tashi lama <[email protected]>
To   <[email protected]>
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)

"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... 


*   For searches and help try:

© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index