问题描述
因此,定义一个名为"Z"的矩阵并显示其第一个元素会很好:
So defining a matrix named "Z", and displaying its first element works nicely:
. matrix Z = J(1,3,0)
. matrix list Z
Z[1,3]
c1 c2 c3
r1 0 0 0
. di el(Z,1,1)
0
另一方面,仅将名称更改为"P"会破坏el()
的功能:
On the other hand simply changing the name to "P" breaks the function of el()
:
. matrix P = J(1,3,0)
. matrix list P
P[1,3]
c1 c2 c3
r1 0 0 0
. di el(P,1,1)
type mismatch
为什么?
更新1:
在发现上述行为时(在调试会话期间),我从命令行和ado文件进行了复制,然后在用clear
,drop program _all
和matrix drop _all
清除了Stata之后进行了复制.但是,重新启动Stata后,我无法重现该行为.
While finding the above behavior (during a debug session), I reproduced from command line and from an ado file, then reproduced after clearing Stata with clear
, drop program _all
and matrix drop _all
. However, upon restarting Stata, I am unable to reproduce the behavior.
更新2:
至少我曾经使用过clear
... ...进一步的研究表明,如果我在内存中有一个名称以"P"开头的变量,则可以在重新启动时重现该行为.例如(重新开始Stata):
At least I thought I used clear
... further investigation shows that I can reproduce the behavior on restart if I have a variable with a name starting with "P" in memory. For example (starting Stata fresh):
. matrix P = J(1,3,0)
. matrix list P
. di el(P,1,1)
0
. set obs 100
obs was 0, now 100
. gen Parsnips = uniform()
(100 real changes made)
. di el(P,1,1)
type mismatch
. rename Parsnips parsnips
. di el(P,1,1)
0
推荐答案
在我的第二次更新表明的情况下,Indeed Stata确实与命名歧义冲突.根据我刚从他们的技术支持部门获得的反馈,使用di el(matrix(P),1,1)
明确地将P
称为矩阵可以解决此问题.
Indeed Stata does collide with naming ambiguity in such a case as my second update indicates. Per feedback I just received from their technical support, using di el(matrix(P),1,1)
to explicitly refer to P
as a matrix resolves this issue.
这篇关于Stata是否会在名为"P"的矩阵上窒息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!