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 on April 23, and its replacement, statalist.org is already up and running.


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

Re: st: switch within do file from Stata 64bit to Stata 32bit


From   Max Bo <boh_max@web.de>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: switch within do file from Stata 64bit to Stata 32bit
Date   Thu, 07 Feb 2013 14:08:23 +0100

Hi Raoul,

i wrote an ado file that calls stata32 using the "shell" command, loads data from an access database via odbc, saves them to a tempfile and reads the data into stata 64 bit. It can be used like the normal odbc-command (but might have some bugs - not all syntax options are tested).
It can also be used to write into a database
If its run from a 32-bit-stata, it just calls the normal odbc command.

Please Note:
Stata 32bit must be in the same folder as the 64bit version and named StataSE-32.exe
If you use Stata ME, please change the code.

I hope that helps,

Cheers
Max



odbc32.ado

version 12
capture program drop odbc32

program define odbc32
// syntax [anything] [if] [in] [using] [, dialog(passthru) dsn(passthru) table(passthru) exec(passthru) load_options(passthru) connect_options(passthru) clear]
  if `c(bit)'==32 {
// odbc `anything' `if' `in' `using', `dialog' `dsn' `table' `exec' `load_options' `connect_options' `clear'
    odbc `0'
  }
  else {
      local commandstr = substr(trim("`0'"),1,4)
      di "`commandstr'"
      local currentdir = "`c(pwd)'"
      // di "`currentdir'"
      local tempdofile = "`c(tmpdir)'z.do"
      qui di "`tempdofile'"
      capture file close tempdo
      file open tempdo using `tempdofile' , write replace
// file write tempdo `"odbc `anything' `if' `in' `using', `dialog' `dsn' `table' `exec' `load_options' `connect_options' `clear'"' _n
      file write tempdo `"odbc `0'"' _n
      if "`commandstr'" == "load" {
          file write tempdo `"odbc `0'"' _n
          file write tempdo `"save `c(tmpdir)'z.dta, replace"' _n
      }
      else {
          save `c(tmpdir)'z.dta, replace
          // di `"`0'"'
          local newcommand = subinstr(`"`0'"',"create","overwrite",1)
          // di `"`newcommand'"'
          file write tempdo `"use `c(tmpdir)'z.dta, clear"' _n
          file write tempdo `"capture odbc `0'"' _n
          file write tempdo `"if "'
          file write tempdo "`"
//          file close tempdo
          file write tempdo `"r(sqlerror)"'
          file write tempdo "'"
          file write tempdo `" == -1 {"' _n
          file write tempdo `"    odbc `newcommand'"' _n
          file write tempdo `"}"' _n
      }
      file close tempdo
      qui cd "`c(tmpdir)'"
      shell "`c(sysdir_stata)'StataSE-32.exe" -e do `tempdofile'
      qui cd "`currentdir'"
      if "`commandstr'" == "load" {
          use "`c(tmpdir)'z.dta", clear
      }
    }
end

exit



Am 07/02/2013 11:41, schrieb Nick Cox:
Setting -version- usually does far less than users imagine, but that
seems a side-issue here. (In essence, it is only what -help version-
indicates.)

I imagine that what you might need to do is run a batch job running
different Statas in sequence.

Calling one Stata from another sounds tricky at best and a nightmare
at worst. At a minimum you would need to -save- your data from one
Stata before you read it into the other Stata. How would the first
Stata know when the second Stata had finished.

My wild guess is that this implies much more than -winexec- or a shell
call, but you may well get much better advice from people who have
done, or tried to do, something similar.

Nick

On Thu, Feb 7, 2013 at 10:24 AM, Raoul Reulen <r.c.reulen@bham.ac.uk> wrote:

I am currently running Stata MP 12-64 bit and all works fine, but now I want to run a part of my do-file in Stata 11-32 bit because it contains reading in some MS Access tables through an odbc connection (which I cannot get to work in Stata 12 -64 bit btw). Simply using "version" control and setting the version to 11 does not seem to work.

It is possible to have the do file call Stata 11-32 bit, run part of my do-file in Stata 11 32-bit and then run the remainder of my do-file in Stats 12 64-bit? I presume I would have to use .winexec or .shellout , but how exactly?
*
*   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