Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: Compund quotes and the -file write- command


From   "Eva Poen" <[email protected]>
To   [email protected]
Subject   st: Compund quotes and the -file write- command
Date   Thu, 9 Aug 2007 12:48:58 +0100

Dear all

I am currently working with a large number of data sets (Stata 9)
which all have a common structure and more or less the same variables.
To ensure that variables are labeled consistently across data sets, I
wrote a little program which defines these labels from information
stored in an Access database. Everything works fine apart from one
thing: I cannot have double quotes inside my variable labels. I tried
numerous ways to incorporate compound quotes, to no avail.

The relevant code follows below. There are two variables in memory at
this point: one is called VarName; it holds all variable names for
which I want to have common labels. The other one is VarLabel which
holds the label information. The code generates a do-file which I can
then run on my data sets as required.

*************
count
local n = r(N)

file open VarLabelsFile using VarLabelsFile.do, write replace

forvalues x = 1/`n' {
    file write `handle' `"capture label variable `=VarName[`x']'
"`=VarLabel[`x']'" "' _n
}

file close VarLabelsFile
*************

My attempt was to introduce compound quotes like this:
-file write `handle' `"capture label variable `=VarName[`x']'
`"`=VarLabel[`x']'"' "' _n-

But the resulting do-file still ends up looking like this:

capture label variable SessionID "zTree (or other) Session ID (alpha-numeric)"
capture label variable SID "unique Session ID (numeric)"
etc.

instead of like this:
capture label variable SessionID `"zTree (or other) Session ID
(alpha-numeric)"'
capture label variable SID `"unique Session ID (numeric)"'
etc.

How can I achieve the latter?
Kind regards,
Eva Poen
*
*   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