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: How to run same code on multiple datasets
From
"Furner, Zhan" <[email protected]>
To
"[email protected]" <[email protected]>
Subject
RE: st: How to run same code on multiple datasets
Date
Thu, 28 Nov 2013 03:36:39 +0000
Yes you're exactly right Sergiy! And I use "aaa" just for illustration purposes, but your advice is definitely well taken! Thank you so much!
Zhan Z. Furner, CPA
Ph.D. Candidate
Rawls College of Business
Texas Tech University
[email protected]
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of Sergiy Radyakin
Sent: Wednesday, November 27, 2013 9:01 PM
To: [email protected]
Subject: Re: st: How to run same code on multiple datasets
Zhan, you probably need save `"`aaa'"', replace. And perhaps something better than "aaa", perhaps "oneFile" for readability. Best, Sergiy Radyakin
On Wed, Nov 27, 2013 at 9:54 PM, Furner, Zhan <[email protected]> wrote:
> Hello all,
>
> I'm trying to create a do file (see below) that would allow me to run the same code on multiple datasets (the first dataset is yearind19902, then yearind19903...). I think the file runs well for the first dataset because the variable 'ratio' is created correctly in the first dataset. However, Stata stopped executing for the rest of datasets and I got an error message as follows:
> invalid `"yearind19903.dta'
> r(198);
>
>
> ***Begin Code ****
>
> local workdir "C:\xxx\xxx\xxx"
> cd `workdir'
> local files: dir "`workdir'" files "*.dta"
>
> foreach aaa of local files {
> use `aaa'
> sort plan
> count if plan<1
> gen n1=r(N)
> count if plan>0
> gen n2=r(N)
> gen ratio=n1/n2 if plan<1
> replace ratio=1 if missing(ratio)
>
> save `files', replace
> }
>
> *** End Code ***
>
>
> How should I amend my code to fix this problem?
>
> Thank you so much and happy Thanksgiving!
>
> Zhan
>
>
>
>
>
>
>
>
> *
> * 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/
*
* 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/