필터 지우기
필터 지우기

How do I import .dta from Stata file into MATLAB?

조회 수: 114 (최근 30일)
JBA Miller
JBA Miller 2022년 2월 12일
댓글: Kai 2024년 4월 5일
Hey community!
I fail to import a .dta data file which should be used by STATA into Matlab. I would need to work with it on Matlab. When I try to import I sometimes get a table in MATLAB, however it is not filled with the actual numerical data but instead with weird text signs... I can't manage.
I attached the file as well, maybe you can help here?
Thanks, best!
  댓글 수: 1
Voss
Voss 2022년 2월 12일
I don't know much about STATA, but can you open this file back in STATA and re-export it as another type that MATLAB can handle, e.g., .xlsx or .csv?

댓글을 달려면 로그인하십시오.

답변 (1개)

Lokesh
Lokesh 2023년 10월 6일
Hi Miller,
I understand that you want to import .dta file into MATLAB.
To import the .dta file into MATLAB, we need to first convert .dta file to csv format and then import in MATLAB using readtable.
Please refer to the following steps to import .dta file into MATLAB:
1.Convert the .dta file to csv format:
  • Open the file in Stata and export it as csv file
  • If you do not have access to Stata, you can use Python with Pandas library to convert .dta file to csv. Please refer to the following example code snippet for file conversion:
import pandas as pd
data = pd.io.stata.read_stata('my_stata_file.dta')
data.to_csv('my_stata_file.csv')
2.Once the .dta file is converted to CSV, you can import the data into MATLAB using the readtable function.Here is an example:
Data1 = readtable(my_stata_file.csv);
Please refer to following documentation to know more about “readtable function in MATLAB:
I hope you find this helpful.
Best Regards,
Lokesh
  댓글 수: 1
Kai
Kai 2024년 4월 5일
No.
You don't have to convert .DTA file into other type. Find your file, right click import and in Import selection, you can find the script you need.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Standard File Formats에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by