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

st: RE:   st: RE: Creating a variable from comments/header in a .txt file


From   "Nick Cox" <n.j.cox@durham.ac.uk>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE:   st: RE: Creating a variable from comments/header in a .txt file
Date   Thu, 14 Apr 2005 20:19:58 +0100

Naturally. I would use a local myself. 

local file = pl[1] 

Nick
n.j.cox@durham.ac.uk 

N.B. Please send just plain text to Statalist. 

Juan Solon

Dear Nick, 
Thank you for your reply. 
I now understand that pl[1] or varname[1] refers to the contents of the varname. I was able to successfully replace the redundant macros in the first half of the do file and save the file using the contents variable pl. . . . 
infile using eli2.dct, clear 
. . 
gen pl=substr(plate,18,6) /* this is data from the first line : in this case "10u5uc"*/ 
. . 
save `=pl[1]', replace 
*this then saves the data as 10u5uc.dta 


However, I need to read in another set of data, and it appears that the reference to pl[1] disappears 
merge obsno using "`=pl[1]'" 
pl not found 
invalid file specification 
r(198); 


Is there a way to save as a global macro and then delete it after I am done with it? 
Juan 






--- 
I'll try the easier part of this. Once your filename is in pl[1] 
you can refer to that on the fly by `=pl[1]' 
so your -merge- command would then be 


merge obsno using `=pl[1]', keep(pl) 


The command 
replace pl ="10u5uc" if _merge==1 


would more generally be 
replace pl = pl[1] if _merge == 1 


if I understand you correctly. 


Nick 
n.j.cox@durham.ac.uk 


*
*   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–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index