Statalist The Stata Listserver


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

[no subject]



 IIRC, Stata -- like many other programming languages -- interprets the \ as
an "escape" character, meaning: "rather than interpret the next character in
a programming context, interpret it literally." That is, by placing \` in
your command, you told Stata, "I really want a ` in the file name, rather
than use the ` to signify the beginning of a macro substitution."

By using \\, you "escaped the escape" -- you told Stata: \ = "interpret the
next character literally" + \ = "as a backslash", which placed the backslash
in the file name. Notice that the second \ is interpreted literally instead
of as an escape character, so the ` began the macro substitution as you
expected.
****************

Best wishes

Stefan


Dr. Stefan Gawrich
Hesse State Health Office 
Wolframstrasse 33 
35683 Dillenburg 
Germany


> 
> Is it possible to use the foreach function for part of the 
> name of a file or
> part of a variable name?
> I would like to write something similar to what below (in 
> which there is
> something wrong, but I do not know if it is only a matter of 
> quotes or so or
> it is not possible to do what I want to do), where the x 
> indicates the wave
> so that the file has the same name just differing in the wave 
> they were
> collected, as well as the variable sin the files, they are 
> the same but they
> are preceeded by a letter indicating the wave.
> 
> foreach x in a b c d e f g h u j k l m n o p q r s t u {
> use "D:\Project\Data_anal\GSOEP\CD1984-2004\"`x'"kind.dta"
> sort persnr 
> save "D:\Project\Data_anal\GSOEP\CD1984-2004\"`x'"kind.dta", replace
> use "D:\Project\Data_anal\GSOEP\My analyses\temp\"`x'"p_mar.dta"
> sort persnr 
> merge using 
> "D:\Project\Data_anal\GSOEP\CD1984-2004\"`x'"kind.dta", keep
> ("`x'"kzahl "`x'"hhgr)
> drop _merge 
> save "D:\Project\Data_anal\GSOEP\My 
> analyses\temp\"`x'"p_mar.dta", replace
> }
> 
> 
> *
> *   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/
> 
*
*   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