Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Is it possible to edit STATA do-files within VBA? (Or the other way around?)

    Hello,

    I have Stata 12 installed on my computer (I'll include a picture of the folder at the end of this post). I do not have administrator rights on my computer, but I can have them temporarily added if necessary. I create dozens of do-files, based on the criteria of an Excel spreadsheet. I read this link on STATA automation, but I run into some issues:
    1. The article says to load the STATA directory into the cmd prompt, and then type "StataSE /Regserver"
      • This command "is not recognized as an internal or external command, operable program, or batch file"
      • I assumed I should change the STATASE to Stata-64 (the name of the file on my computer). When I run this command, I don't get an error, but I also don't get any sort of message that suggests it was successful.
    2. A member of another forum suggested typing regsvr32 DLXAPI32.dll ​into cmd prompt. When I do that, I get the following erorr:
      • The module "DLXAPI32.DLL" was loaded but the entry-point DllRegisterServer was not found. Make sure that "DLXAPI32.DLL" is a valid DLL or OCX file and then try again.
      • This same error happens when I type regsvr32 DLXAPI64.dll. These are the only two .dll files in the folder
    3. The article says to go to tools > add reference - then add COM, in which the STATA plugin is apparently located
      • There is no such plugin found in VBA. I can hit "browse", and locate the two DLL files, but both give the following error:
        • "Can't add a reference to the specified file."
    4. A member on another forum suggested running the following code:
      • Code:
        		Private Declare Function CeGetDeviceId Lib "C:\Program Files (x86)\Stata12\DLXAPI32.DLL" () As Boolean
        		Sub test()
        		
        		
        		If CeGetDeviceId() = False Then
        		    MsgBox "Test"
        		End If
        		
        		        
        		End Sub
      • When I run the code with 32I get the following error:
        • Run-time error '453': Specified DLL function not found
      • When I run the code with 64 I get the following error:
        • Run-time error '48': Error in loading DLL
    Is there something else I should be doing? I have tried googling this info, but have been unable to find any information related to my situation. If VBA absolutely will not work with STATA, my plan B would be to somehow use a STATA macro to read an Excel file and create do-files, based on specifications in the Excel file (I would appreciate any links about this subject - but again this is my plan B).


    Thank you very much for any help. Here is a picture of the folder mentioned:



  • #2
    I'd personally suggest using your plan B approach for a few reasons. The first is that it will be easily portable (e.g., you can build the solution once and it will be platform independent) and is easier to maintain (e.g., don't need to compile any source or store code in macros embedded in the file). The program below is something I put together with a colleague a little while ago. The first part of the program involves downloading a giant code book file that is stored in excel. The data from the excel file gets cleaned a bit and is used to write the code needed to read the actual data, format, clean, and label it. I've had to do similar things when working with fixed width formatted files from assessment vendors. One of the nice things about Stata for metaprogramming is the way macro expansion works, makes it very easy to exploit metaprogramming to do a lot of heavy lifting for you.
    Attached Files

    Comment


    • #3
      You have to have administrator right to register Stata OLE automation object.

      You need either follow the instruction for Windows Vista or beyond:
      1. In the installation directory, right-click on the Stata executable, for example, StataSE.exe. Choose "Create Shortcut".
      2. Right-click on the newly created "Shortcut to StataSE-64.exe", choose "Property", and change the Target from "C:\Program Files\Stata12\StataSE-64.exe" to "C:\Program Files\Stata12\StataSE-64.exe" /Register. Click "OK".
      3. Right-click on the updated "Shortcut to StataSE.exe"; choose "Run as administrator".
      Or to manually register the type library, do the following steps:
      1. From the Start menu, select Run, enter cmd, the right click on cmd.exe, then "run as Administrator". It is very important to run the Windows command window as administrator, otherwise Step 3 will fail.
      2. Change the directory to the directory with the Stata executable.
      3. Type StataSE-64.exe /Register or StataSE-64.exe /Regserver
      Either way, you must have administrator right to register Stata OLE automation object.

      Just FYI, DLXAPI32.dll is a dll to interface with Haver data and is used for -import haver- command. It has nothing to do with Stata OLE automation.


      Comment

      Working...
      X