从Matlab导出到Stata的是数字和字符串数组 [英] Export from Matlab to Stata an array of numbers and strings

查看:159
本文介绍了从Matlab导出到Stata的是数字和字符串数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将一个数字和字符串数组从Matlab导出到Stata。

I need to export from Matlab to Stata an array of numbers and strings.

例如:

clear

r=2;
n=4;
X=unifrnd(0,1,r,n);

X_STATA=reshape(X.', r*n,1);
id_STATA=kron((1:1:r).', ones(n,1));
mode_STATA=repmat(["AIR"; "TRAIN"; "BUS"; "CAR"],r,1);

在这里,我要导出 X_STATA id_STATA mode_STATA

Here, I want to export X_STATA, id_STATAand mode_STATA.

我该怎么做?

特别是,我想确保 X_STATA 条目的逗号后的数字能正确导出,没有不适当的近似值。

In particular, I want to make sure that the numbers after the comma of the entries of X_STATA are well exported, without inappropriate approximations.

推荐答案

在Matlab中,您可以执行以下操作:

In Matlab you can do the following:

writematrix(X_STATA, 'myfile.csv', 'precision', 17)

在Stata中,您可以像这样导入数据:

In Stata you import the data like this:

import delimited myfile.csv, asdouble

这篇关于从Matlab导出到Stata的是数字和字符串数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆