Replace $ in Stata variable labels with \textdollar -


i have variables dollar signs (i.e., $) in variable labels. causes problems downstream in code (i later modify these labels , dollar signs deregister empty global macros). replace these dollar signs latex's \textdollar using stata's subinstr() function.

but can't figure out. possible? or should resign doing more manually? or looking other characters near or around $ in variable labels?

clear set obs 10 generate x = runiform() label variable x "label $mil" generate y = runiform() label variable y "another label $mil"  describe foreach v of varlist * {     local name : variable label `v'     local name `=subinstr("`name'", "$mil", "\textdollar", .)'     label variable `v' "`name'" } describe 

this removes label altogether.

(the problem has changed, why give separate answer.)

having $something in variable label problematic because stata treat macro , therefore dereference it. stata doing in toy example? let's see:

this expected behavior:

. local name = subinstr("some text", " ", "xyz", .)  . display "`name'" somexyztext 

the following, don't know if documented, not expected crucial in understanding:

. local name = subinstr("some text", "", "xyz", .)  . display "`name'"  . (blank) 

i put in last line emphasize local name has nothing.

in code stata dereferences $mil nothing (because it's not declared beforehand; it's not meant to, of course). in fact,

label variable x "label $mil" 

does not hold intend. rather want delay macro substitution \:

label variable x "label \$mil" 

for other part, when run this

local name `=subinstr("`name'", "$mil", "\textdollar", .)' 

it evaluates to

local name `=subinstr("`name'", "", "\textdollar", .)' 

and local name holds nothing. ends story of why code does.

a solution might be:

clear  set obs 10  generate x = runiform() label variable x "label \$mil"  generate y = runiform() label variable y "another \$mil"  describe  *-----  foreach v of varlist _all {      local name : variable label `v'     label variable `v' "`=subinstr("`name'\$mil", "\$mil", "\textdollar", .)'" }  describe 

but works if $mil @ end of label text. if in middle somewhere, strategy must used.

all on stata 12.1.


Comments

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -