Does Stata choke on matrices named “P”?

天大地大妈咪最大 提交于 2019-12-11 10:49:25

问题


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

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

Why?

Update 1:

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.

Update 2:

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

回答1:


This works fine for me:

matrix Z = J(1,3,0)
matrix list Z

di el(Z,1,1)

matrix P = J(1,3,0)
matrix list P

di el(P,1,1)

Are you omitting information?




回答2:


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.



来源:https://stackoverflow.com/questions/25693145/does-stata-choke-on-matrices-named-p

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!