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: use of tempfile


From   Eduardo Montoya <[email protected]>
To   [email protected]
Subject   Re: st: use of tempfile
Date   Fri, 20 Apr 2012 00:02:11 -0700

I don't understand what you're trying to do, but maybe this is what
you're looking for.

* Creates 20 temporary files
forvalues i = 1/20 {
   use sales1.dta, clear
   keep if sate_code==`i'
   ren  sate_code sate_code1
   ren exp_val exp_val1
   ren sales_val sales_val1
   tempfile sales1_`i'
   save `sales1_`i'', replace
}

* Merge
use `sales1_1', clear
save sales1_1_20, replace
forvalues i = 2/20 {
   merge common_id using `sales1_`i'', sort
   tab _merge
   drop _merge
   save sales1_1_20, replace
}


On Thu, Apr 19, 2012 at 5:10 AM, Prakash Singh <[email protected]> wrote:
> Nick I beg to differ you
> I have done using stata programming what I intend to do but then I
> thought why to have unnecessarily the data file which I do not want. I
> ma definite about reshape and separate would not do good.
>
> Let me try final time to explain what I am interested in doing.
>
> suppose we use this sales1.data and do
>
> use sales1.dta, clear
> keep if sate_code==1
> ren  sate_code sate_code1
> ren exp_val exp_val1
> ren sales_val sales_val1
> save sales1_1.data, replace
> .
> .
> .
> use sales1.dta, clear
> keep if sate_code==20
> ren  sate_code sate_code20
> ren exp_val exp_val20
> ren sales_val sales_val20
> save sales1_20.dta, replace
>
> use sales1_1.data, clear
> merge common_id using sales1_2.dta
> save sales1_1_2.dta
> .
> .
> .
> use sales1_1_19.data, clear
> merge common_id using sales1_20.dta
> save sales1_1_20.dta
>
> But this way I have 40 data file but what I am trying to in the code
> posted in first mail is to have only one file finaly i.e.
> sales1_1_20.dta
>
> Thanks
> Prakash
> *
> *   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/


© Copyright 1996–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index