Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Single quotes and macro expansion


From   "Jann, Ben" <[email protected]>
To   <[email protected]>
Subject   st: Single quotes and macro expansion
Date   Sat, 17 Jan 2004 01:27:12 +0100

Hi all,

single quotes in strings (e.g., a value label 
"don't know") sometimes seem to mess up macro 
expansion even if compound double quotes are 
used. Here's an example: The code

 local a `"this'n'that"'
 local b: piece 1 6 of `"`a'"'
 display `"`b'"'

works fine, while the logically equivalent (at
least it looks equivalent to me)

 local a `"this'n'that"'
 display `"`:piece 1 6 of `"`a'"''"'

does not. Can anyone explain to me, why? 

I repeatedly ran into this problem and 
sometimes it is very unpleasant. For example,
occasionally I'd like to use loops like 

 while `"`:piece `i' 6 of `"`a'"''"'!="" {
  ...
  local i=`i'+1
  }

However, this does not work if `a' contains
single quotes and there is no easy fix for it.

Any help will be appreciated

ben

--------------------------
Swiss Federal Institute 
of Technology Zurich (ETH)
Sociology
ETH Zentrum SEW E 28
CH-8092 Zurich

Ben Jann, lic. rer. soc.
Tel. +41 1 632 55 58
Fax  +41 1 632 10 54
[email protected]
http://www.socio.ethz.ch/

*
*   For searches and help try:
*   http://www.stata.com/support/faqs/res/findit.html
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/



© Copyright 1996–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index