sysuse
- 导入Stata自带数据文件
- 不用指定路径
use
- 导入Stata格式文件(.dta)
- 需指定路径,默认工作路径
insheet、outsheet
- 无法导入dta
- 只能导入/导出tab或逗号分隔的数据文件(.csv/.txt)
infile、outfile
- 与insheet基本相同
- 能导入空格分隔的数据文件
- 必须指明变量名称!!
- 导入字符时要指定格式!
xmluse、xmlsave
- 导入excel数据
- 先把.xls保存为.xml
- firstrow表示第一行为变量名称
xmluse data.xml, doctype(excel) clear firstrow
xpose
- 行列互换
. insheet using hs0.csv, clear
(11 vars, 200 obs)
. insheet using nerlove.txt, clear
(5 vars, 145 obs)
. type nerlove.txt
TC Q PL PF PK
0.082 2 2.1 17.9 183
0.661 3 2.1 35.1 174
0.99 4 2.1 35.1 171
0.315 4 1.8 32.2 166
0.197 5 2.1 28.6 233
0.098 9 2.1 28.6 195
0.949 11 2.0 35.5 206
0.675 13 2.1 35.1 150
0.525 13 2.2 29.1 155
0.501 22 1.7 15.0 188
1.194 25 2.1 17.9 170
0.67 25 1.7 39.7 167
0.349 35 1.8 22.6 213
0.423 39 2.3 23.6 164
0.501 43 1.8 42.8 170
0.55 63 1.8 10.3 161
0.795 68 2.0 35.5 210
0.664 81 2.3 28.5 158
0.705 84 2.2 29.1 156
0.903 73 1.8 42.8 176
1.504 99 2.2 36.2 170
1.615 101 1.7 33.4 192
1.127 119 1.9 22.5 164
0.718 120 1.8 21.3 175
2.414 122 2.1 17.9 180
1.13 130 1.8 38.9 176
0.992 138 1.8 20.2 202
1.554 149 1.9 22.5 227
1.225 196 1.9 29.1 186
1.565 197 2.2 29.1 183
1.936 209 1.9 22.5 169
3.154 214 1.5 27.5 168
2.599 220 1.9 22.5 164
3.298 234 2.2 36.2 164
2.441 235 2.1 24.4 170
2.031 253 1.9 22.5 158
4.666 279 2.1 35.1 177
1.834 290 1.7 33.4 195
2.072 290 1.8 20.2 176
2.039 295 1.8 21.3 188
3.398 299 1.7 26.9 187
3.083 324 2.1 35.1 152
2.344 333 2.2 29.1 157
2.382 338 1.9 24.6 163
2.657 353 2.2 29.1 143
1.705 353 2.1 10.7 167
3.23 416 1.5 26.2 217
5.049 420 1.5 27.5 144
3.814 456 2.1 30.0 178
4.58 484 1.8 42.8 176
4.358 516 2.3 23.6 167
4.714 550 2.1 35.1 158
4.357 563 2.3 31.9 162
3.919 566 2.3 33.5 198
3.442 592 1.9 22.5 164
4.898 671 2.1 35.1 164
3.584 696 1.8 10.3 161
5.535 719 1.7 26.9 174
4.406 742 2.0 20.7 157
4.289 795 2.2 26.5 185
6.731 800 1.7 26.9 157
6.895 808 1.7 39.7 203
5.112 811 2.3 28.5 178
5.141 855 2.0 34.3 183
5.72 860 2.3 33.5 168
4.691 909 1.5 17.6 196
6.832 913 1.7 26.9 166
4.813 924 1.8 10.3 172
6.754 984 1.7 26.9 158
5.127 991 2.1 30.0 174
6.388 1000 1.6 28.2 225
4.509 1098 2.1 24.4 168
7.185 1109 2.1 35.1 177
6.8 1118 2.3 23.6 161
7.743 1122 2.2 29.1 162
7.968 1137 2.0 20.7 158
8.858 1156 2.3 33.5 176
8.588 1166 1.7 26.9 183
6.449 1170 2.1 35.1 166
8.488 1215 2.2 29.1 164
8.877 1279 2.0 34.3 207
10.274 1291 2.3 31.9 175
6.024 1290 1.6 28.2 225
8.258 1331 2.1 30.0 178
13.376 1373 2.2 36.2 157
10.69 1420 2.2 36.2 138
8.308 1474 1.9 24.6 163
6.082 1497 1.8 10.3 168
9.284 1545 1.8 20.2 158
10.879 1649 2.3 31.9 177
8.477 1668 1.8 20.2 170
6.877 1782 2.1 10.7 183
15.106 1831 2.0 35.5 162
8.031 1833 1.8 10.3 177
8.082 1838 1.5 17.6 196
10.866 1787 2.2 26.5 164
8.596 1918 1.7 12.9 158
8.673 1930 1.8 22.6 157
15.437 2028 2.1 24.4 163
8.211 2057 1.8 10.3 161
11.982 2084 1.8 21.3 156
16.674 2226 2.0 34.3 217
12.62 2304 2.3 23.6 161
12.905 2341 2.0 20.7 183
11.615 2353 1.7 12.9 167
9.321 2367 1.8 10.3 161
12.962 2451 2.0 20.7 163
16.932 2457 2.2 36.2 170
9.648 2507 1.8 10.3 174
18.35 2530 2.3 33.5 197
17.333 2576 1.9 22.5 162
12.015 2607 1.8 10.3 155
11.32 2870 1.8 10.3 167
22.337 2993 2.3 33.5 176
19.035 3202 2.3 23.6 170
12.205 3286 1.6 17.8 183
17.078 3312 1.7 28.8 190
25.528 3498 2.1 30.0 170
24.021 3538 2.1 30.0 176
32.197 3794 2.1 35.1 159
26.652 3841 2.3 28.5 157
20.164 4014 2.1 24.4 161
14.132 4217 1.5 18.1 172
21.41 4305 2.1 24.4 203
23.244 4494 2.0 20.7 167
29.845 4764 2.2 29.1 195
32.318 5277 1.9 29.1 161
21.988 5283 2.0 20.7 159
35.229 5668 2.1 24.4 177
17.467 5681 1.8 10.3 157
22.828 5819 1.8 18.5 196
33.154 6000 2.1 24.4 183
32.228 6119 1.5 26.2 189
34.168 6136 1.9 22.5 160
40.594 7193 2.1 28.6 162
33.354 7886 1.6 17.8 178
64.542 8419 2.3 31.9 199
41.238 8642 2.2 26.5 182
47.993 8787 2.3 33.5 190
69.878 9484 2.1 24.4 165
44.894 9956 1.7 28.8 203
67.12 11477 2.2 26.5 151
73.05 11796 2.1 28.6 148
139.422 14359 2.3 33.5 212
119.939 16719 2.3 23.6 162
. infile v1-v5 using nerlove.txt, cleear
you must start with an empty dataset
r(18);
. infile v1-v5 using nerlove.txt, clear
'TC' cannot be read as a number for v1[1]
'Q' cannot be read as a number for v2[1]
'PL' cannot be read as a number for v3[1]
'PF' cannot be read as a number for v4[1]
'PK' cannot be read as a number for v5[1]
(146 observations read)
. infile str21 v1-v5 using nerlove.txt, clear
(146 observations read)
. infile str v1-v5 using nerlove.txt, clear
'TC' cannot be read as a number for str[1]
'Q' cannot be read as a number for v1[1]
'PL' cannot be read as a number for v2[1]
'PF' cannot be read as a number for v3[1]
'PK' cannot be read as a number for v4[1]
(eof not at end of obs)
(122 observations read)
. infile str5 v1-v5 using nerlove.txt, clear
(146 observations read)
. type canada.raw
"Canada" 29606.1 10.6 75.1 81.1
"Newfoundland" 575.4 19.6 73.9 79.8
"Prince Edward Island" 136.1 19.1 74.8 81.3
"Nova Scotia" 937.8 13.9 74.2 80.4
"New Brunswick" 760.1 13.8 74.8 80.6
"Quebec" 7334.2 13.2 74.5 81.2
"Ontario" 11100.3 9.3 75.5 81.1
"Manitoba" 1137.5 8.5 75 80.8
"Saskatchewan" 1015.6 7 75.2 81.8
"Alberta" 2747 8.4 75.5 81.4
"British Columbia" 3766 9.8 75.8 81.4
"Yukon" 30.1 -999 71.3 80.4
"Northwest Territories" 65.8 -999 70.2 78
.