Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: st: problem calling macros using file write in a program
From
"Martin Weiss" <[email protected]>
To
<[email protected]>
Subject
RE: st: problem calling macros using file write in a program
Date
Wed, 17 Mar 2010 10:42:54 +0100
<>
" Anyway, I appreciate it and will see if I can figure out a smooth way
to automate the process."
Before proceeding, you want to be extra sure that there is no -ssc- solution
to your problem. I could see you trying -ssc d esttab- by Ben Jann, and only
if the functionality you want is not there should you write your own
-program-...
HTH
Martin
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Tim Scharks
Sent: Mittwoch, 17. März 2010 00:57
To: [email protected]
Subject: Re: st: problem calling macros using file write in a program
Hi Eric, problem 1 was OK--I drafted that in a hurry and understand
the error, thanks though.
part 2 is right on; I did run the trace and saw that it was writing ""
to the file but couldn't figure out why, not understanding how to have
the local passed through to the program; that helps a lot, thank you!!
Unfortunately it doesn't make it very easy to simplify the routines I
want to run. My star writing program would just run and call the
values in memory without having to specify anything after the command.
Anyway, I appreciate it and will see if I can figure out a smooth way
to automate the process.
Best regards, Tim
On Tue, Mar 16, 2010 at 4:22 PM, Eric Booth <[email protected]> wrote:
>
>
> Hi Tim:
> One problem is that you -file open-/-file write- to the handle "results"
and you -file close- the handle "test".
>
> Second, if you -set trace on- before you run your program, you'll see that
it's not writing `model' because the
> program is not passed `model', so it writes what it sees (e.g., " file
write results `""' ")
>
> Instead, you might want to pass the 'using' file and the local macro as
part of the syntax; something like this should
> get you started:
>
> **********
> cap erase "OLSresults.txt" //--just so that we know that this program
wrote the macro
> **
>
> cap program drop writeit
> program define writeit
> syntax using/ , LOCal(string)
> cap file close results
> file open results using "`using'", write replace
> file write results `"`local'"'
> file close results
> end
>
> **examples**
> writeit using "OLSresults.txt", local("Model 1. All States, no controls.")
> set trace on
> writeit using "OLSresults2.txt", loc("Model 2. Yada Yada")
> set trace off
> **********
>
> ~ Eric
> __
> Eric A. Booth
> Public Policy Research Institute
> Texas A&M University
> [email protected]
> Office: +979.845.6754
>
>
>
> On Mar 16, 2010, at 5:32 PM, Tim Scharks wrote:
>
>>
>> local model "Model 1. All states, no controls."
>> file open results using OLSresults.txt, write replace
>> file write results `"`model'"'
>> file close test
>>
>> This works fine--my specified file has the local macro text written to
>> it and I know how to customize with tabs, new lines, and my regression
>> results.
>>
>> However, I would think that the above routine could be made even
>> simpler with a program that would execute from within the .do file. I
>> have already written a small program in this manner to add stars for
>> significance to my regression output using a series of if statements
>> with tests on the p values file write commands. Therefore I thought
>> this would work:
>>
>>
>> program define writeit
>> file open results using OLSresults.txt, write replace
>> file write results `"`model'"'
>> file close test
>> end
>>
>> local model "Model 1. All states, no controls."
>> writeit
>
>
>
> On Mar 16, 2010, at 5:32 PM, Tim Scharks wrote:
>
>> Hi everyone, long time reader, first time asker. I would very much
>> appreciate any light you could shine on this problem.
>>
>> I am trying to write a short program to routinize my results output
>> using file write. Here is a short example of the function I am trying
>> to automate:
>>
>> local model "Model 1. All states, no controls."
>> file open results using OLSresults.txt, write replace
>> file write results `"`model'"'
>> file close test
>>
>> This works fine--my specified file has the local macro text written to
>> it and I know how to customize with tabs, new lines, and my regression
>> results.
>>
>> However, I would think that the above routine could be made even
>> simpler with a program that would execute from within the .do file. I
>> have already written a small program in this manner to add stars for
>> significance to my regression output using a series of if statements
>> with tests on the p values file write commands. Therefore I thought
>> this would work:
>>
>>
>> program define writeit
>> file open results using OLSresults.txt, write replace
>> file write results `"`model'"'
>> file close test
>> end
>>
>> local model "Model 1. All states, no controls."
>> writeit
>>
>>
>> Obviously the program would be longer with more steps to make it
>> useful. But even as written here executing the program writes nothing
>> to my file--with the replace command it wipes it clean but doesn't
>> write anything!?!
>>
>> Any help would be greatly appreciated. Thanks, Tim
>> *
>> * For searches and help try:
>> * http://www.stata.com/help.cgi?search
>> * http://www.stata.com/support/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/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/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/statalist/faq
* http://www.ats.ucla.edu/stat/stata/