5.18.2010

Data transfer from Matlab to Stata and reverse

Zip file with Matlab code to export or import datasets to Stata. For use in conjunction with "insheet/outsheet". Importing data from Stata is restricted to numeric variables (but not the reverse).


(also includes scripts for dropping missing obs in matlab)

enjoy!

http://dl.dropbox.com/u/3011470/stata_translation.zip

-------------------------------------

matlab to stata

in matlab:

cell2csv(cellarrayname, 'dataname')

then in stata:

insheet using dataname.csv

-------------------------------------

stata to matlab

in stata:

outsheet varlist using dataname, comma

then in matlab:

data = csv2mat_numeric('dataname.out')

5 comments:

  1. Hi...

    First - Jesse you were a great TA

    Second - Is there any way to open a matlab file with stata without having matlab?

    ReplyDelete
  2. Thanks My! It doesn't look like there's a straightforward way of doing it without using Matlab itself. Apparently later versions of Matlab save .mat files in a format that can be read with R.

    http://stackoverflow.com/questions/7713422/convert-mat-file-to-r-compliant-file

    Perhaps you could try that?

    ReplyDelete
  3. This could be just what I need! Just a question before I dive into this: I need to run two iterative procedures, one in STATA and on in MATLAB, and I need to send newly created results back and forth from one program to the other, and I need to have this automated as I have hundreds of thousands iterations. So essentially, I need to call a STATA dofile from Matlab as a subroutine, and reverse.

    I presume your command just works interactively (user sitting in front of screen and doing manually),and could not be built into scripts?

    I guess I will have to estimate my model either all in STATA, but I am not happy using MATA, or in MATLAB, but I would need to program my estimator(which is precanned in STATA). Can your command spare me from those options?

    Thanks! Katharina.

    ReplyDelete
    Replies
    1. If your script knows the name of the files you are using, you should be able to automate the transfers of data by calling the function from the script.

      Delete