Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at

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

Re: st: Stata to Matlab

Subject   Re: st: Stata to Matlab
Date   Thu, 19 Apr 2012 17:25:55 +0000

Dear Mario and Wilner,

Thanks very much for your suggestions.

Actually, I tried stattransfer. I would say it is pretty good in dealing with data of reasonable size, such as data smaller than 500m. It can still transfer data bigger than 1G, however, then the matlab can not read the transferred data and report the data as corrupted. I still have not figured out why, maybe some of you guys know the reason, please let me know.

Finally, I end up with a website called Fight Entropy, it has all I need. Just as Wilner recommends, I use -outsheet- to output data from stata, and then use the code on the website to read into Matlab. It takes a while and requires a powerful computer, but it works. The funny thing is that even though I read my data into Matlab, it refuses to save the data as a .mat file, it is just weird. Btw, this is the website


From: "P. Wilner Jeanty" <>
To: "" <>
Sent: April 19, 2012 11:41 AM
Subject: Re: st: Stata to Matlab

On Sun, Apr 15, 2012 at 7:46 AM, Mario Veneziani
> Dear Rui,
> I hope this mine finds you well indeed.
> Unfortunately, I will not be able to respond to your query in full but
> I am able to give you a couple of preliminary tips you might find
> useful in preparing your dataset for import in Matlab if anybody else
> chimes in with additional suggestions.
> First of all, I am aware that Matlab does not accept datafiles
> containing variables stored as strings. It imports only numeric text
> files. Therefore, if your Stata file contains string variables you
> have to drop them before attempting to go to Matlab.
> Second of all, it is my understanding that Matlab treats the name of
> the variables (the columns of the matrix of data it imports) quite
> differently from STATA. It seems to me that you might need to let
> Matlab know the name of the columns (or of the variables) through
> either a variable storing the other variables' names and/or through a
> different text file with names only.
> Having said that, I believe the best strategy to convert the datafile
> from Stata to Matlab is using Stattransfer which will protect you from
> "unusual" behaviours of both Stata and Matlab in the export/import
> procedure (i.e., the addition of hidden characters and their ensuing
> reading as empty columns). Please note that converting a 1 GB Stata
> file into a Matlab one might be highly intensive computationally, so
> either use a powerful computer or exercise your patience. It remains
> to be seen then whether Matlab is like Stata which adds memory to
> accommodate very large datasets. Unfortunately, I never got to verify
> this information myself.
> I hope this helps you, somewhat!
> Best regards
> Mario
> Il 15 aprile 2012 04:59, Rui Zeng  ha scritto:
>> Dear Statalist,
>> Is is possible to read a stata file of size of one gigabyte into matlab? If so, how can I do that? thanks!
>> Rui
>> *
>> *   For searches and help try:
>> *
>> *
>> *
> --
> Mario Veneziani
> Research Assistant
> Istituto di Economia Agroalimentare
> Università Cattolica del Sacro Cuore
> Piacenza, Italy

Dear Rui,

Mario has made some valid points you need to consider in preparing
your data for import into Matlab. But, have you given -outsheet- a
shot? -outsheet- always works for me in importing my data into Matlab.
Admittedly, I have never imported a dataset as large as yours. So,
similar to Mario, I cannot speak to the size issue. If you use
-outsheet-, what you can export to Matlab depends on what -outsheet-
can actually outsheet. After dropping everything you don't need or
anything such as string variables with numeric or alphanumeric
characters that can hinder the import process, you can give a call to
-outsheet- like:

outsheet using filename.dat, nonames nolabel

And in Matlab as you know, you code

load filename.dat;

If Matlab allows you to import more than what -outsheet- can outsheet,
which I doubt, then outsheet bits of data that you can combine in

Please tell us about your experience with -outsheet-



P. Wilner Jeanty, Research Scientist
Rice University
Kinder Institute for Urban Research & Hobby Center for the Study of Texas
6100 Main Street
Houston, Texas
(713) 348-3114

*   For searches and help try:
* * For searches and help try: * * *

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