Bookmark and Share

Notice: On March 31, it was announced that Statalist is moving from an email list to a forum. The old list will shut down at the end of May, and its replacement, statalist.org is already up and running.


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Load data using macro


From   Jeph Herrin <stata@spandrel.net>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Load data using macro
Date   Thu, 13 Jun 2013 10:16:52 -0400

What do you mean by "doesn't work"? The following

 clear
 set obs 100
 gen x=runiform()
 local depvar x
 save `depvar', replace
 u `depvar'


works fine.

Most likely you will want to add quotes and an extension to help disambiguate file names, eg.,:

 clear
 set obs 100
 gen x=runiform()
 local depvar x
 save "`depvar'", replace
 u "`depvar'".dta


hth,
Jeph


On 6/13/2013 9:57 AM, G. Anderson wrote:
Hi,

I am able to save files using the name of a variable in a macro (in this case my dependent variable

So when I type

save `depvar', replace

it saves a file with the name of the dependent variable as my filename.

Unfortunately when loading data

use `depvar'
doesn't work. Any ideas how you can load data using names defined by macros?


Thanks

Gareth
*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/faqs/resources/statalist-faq/
*   http://www.ats.ucla.edu/stat/stata/


© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   Site index