Bookmark and Share

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: RE: Need Help with Stata Programming


From   Michael Stewart <[email protected]>
To   statalist <[email protected]>
Subject   Re: st: RE: Need Help with Stata Programming
Date   Wed, 5 Jun 2013 14:25:19 -0400

Thanks a lot Kieran,The code works  very well.
Sincerely ,
Mike

On Tue, Jun 4, 2013 at 10:50 PM, Kieran McCaul <[email protected]> wrote:
> ...
>
> I think this will solve the first two issues; I don't understand the third because I don't know what file-A and file-B are.
>
> clear *
> global data "D:\_Dummy\multiple"
> global outdata "C:\research\auto"
>
>
> forvalues i = 1/3  {
>         use "$data\\`i'\auto_`i',dta", clear
>         gen x=0 if mpg>25
>         gen y=2 if headroom<5
>         save "$outdata\auto_`i'_new.dta",replace
>         use "$data\\`i'\auto_`i',dta", clear
>         append using "$outdata\auto_`i'_new.dta"
>         save "$outdata\auto_`i'_appended.dta",replace
> }
>
> -----Original Message-----
> From: [email protected] [mailto:[email protected]] On Behalf Of Michael Stewart
> Sent: Wednesday, 5 June 2013 10:03 AM
> To: statalist
> Subject: st: Need Help with Stata Programming
>
> Dear Statalist user ,
>
> I need help with stat porgramming.
>
> I am working with multiple datasets and with the  help of statalist
> users, was able to figure out a way to use multiple datasets, complete
>  data management tasks and save them under separate files
>
> MY DATA STRUCTURE:
> ***************************************************************
> auto-1 contains variables DX1-DX15;  variables DXCCS1-DXCCS-15 + other variables
> auto-2 contains variables DX1-DX25 ;  variables DXCCS1-DXCCS-25  +
> other variables
> auto-3 contains variables DX1-DX35 ;  variables DXCCS1-DXCCS-35  +
> other variables
> ****************************************************************
>
>
> My current code is as follows
> ***********************************************
> local ds1 "D:\_Dummy\multiple\1\auto_1.dta"
> local ds2 "D:\_Dummy\multiple\2\auto_2.dta"
> local ds3 "D:\_Dummy\multiple\3\auto_3.dta"
> local all ds1 ds2 ds3
> foreach x in `all'{
> use ``x'',clear
> gen x=0 if mpg>25
> gen y=2 if headroom<5
> save ``x''_new.dta,replace
> }
> ***********************************************
>
> New Problem:1:
> The files are being saved under the same folder  as the auto-1,auto-2
> files.If I need to store the foled with path C:\research\auto; how can
> I accomplish it (I do not know as the filepath seems to be fixed in
> the ``x'' macro )
>
> NEW PROBLEM-2:
> I need to append file-1 to auto-1 after approproate datamanagement in
> the  loop; append file-2 to auto-2 after approproate datamanagement in
> the  loop; append file-3 to auto-3 after approproate datamanagement in
> the  loop. How can I do it
>
> New Problem-3:
> I need to merge  file-A to auto-1 after approproate datamanagement in
> the  loop; merge  file-B to auto-2 after approproate datamanagement in
> the  loop; merge  file-B to auto-3 after approproate datamanagement in
> the  loop. How can I do it
>
> Please help me
>
> --
> Thank you ,
> Yours Sincerely,
> Mike.
> *
> *   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/



-- 
Thank you ,
Yours Sincerely,
Mike.
*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index