全部版块 我的主页
论坛 计量经济学与统计论坛 五区 计量经济学与统计软件 Stata专版
12069 12
2015-12-02
我已经用spmat导出了空间逆距离(dstate)与空间邻近关系矩阵(cstate),但不知道怎么保存为dta格式,有用mata尝试但不成功,语句如下:

use usdb
. shp2dta using "D:\data\s_10nv15\s_10nv15", database(state) coordinates(statexy) genid(id) gencentroids(c)
. use state
spmat contiguity cstate using statexy, id (id) normalize (minmax)
warning: spatial-weighting matrix contains 4 islands
. spmat summarize cstate, links
Summary of spatial-weighting object cstate
-------------------------------------------
        Matrix |               Description
---------------+---------------------------
    Dimensions |                   53 x 53
     Stored as |                   53 x 53
Links         |
         total |                       208
           min |                         0
          mean |                  3.924528
           max |                         8
-------------------------------------------
warning: spatial-weighting matrix contains 4 islands

. spmat idistance dstate longitude latitude, id (id) dfunction (dhaversine) normalize (minmax)
. spmat summarize dstate
Summary of spatial-weighting object dstate
-------------------------------------------
        Matrix |               Description
---------------+---------------------------
    Dimensions |                   53 x 53
     Stored as |                   53 x 53
Values        |
           min |                         0
         min>0 |                  .0007981
          mean |                  .0104402
           max |                  .1942416
-------------------------------------------
spmat getmat cstate matcstate, id(id)
. spmat getmat dstate matdstate, id(id)


mata describe的结果似乎显示两个权重矩阵已经存在:。
. mata
------------------------------------------------- mata (type end to exit) -------------------------------------------------------: mata describe

      # bytes   type                        name and extent
-------------------------------------------------------------------------------
            8   struct scalar               cstate
            8   struct scalar               dstate
            8   struct scalar               dstateUstd
          424   real colvector              id[53]
       22,472   real matrix                 matcstate[53,53]
       22,472   real matrix                 matdstate[53,53]
-------------------------------------------------------------------------------

Q1: 我尝试将这两个空间权重矩阵,以及相乘之后的新矩阵分别保存。但不知道是哪里出错,一直不成功。
: mate=matcstate*matdstate

: mata describe
      # bytes   type                        name and extent
-------------------------------------------------------------------------------
            8   struct scalar               cstate
            8   struct scalar               dstate
            8   struct scalar               dstateUstd
          424   real colvector              id[53]
       22,472   real matrix                 matcstate[53,53]
       22,472   real matrix                 matdstate[53,53]
       22,472   real matrix                 mate[53,53]
-------------------------------------------------------------------------------

Q2: 想要显示已生成的三个矩阵,不知道应该用什么命令,尝试了st_view不对。
: st_view
                 <istmt>:  3499  st_view not found
r(3499);


保存不成功:
: mata matsave mate
matrix name required
r(100);

: mata matsave mate*
matrix name required
r(100);

: mata matdescribe mate
file mate.mmat not found
r(601);

: mata matuse mate
file mate.mmat not found


Q3: 如何将矩阵根据一个变量而融合进现有数据库?
由于我的目标是将两个矩阵相乘后的得到的矩阵导入我的数据库,对应上100个公司在10年间在50个州的发展数据(比如:分店数)。我想用分店数这个有100*10*50个observation的向量 乘以 空间邻近与逆距离矩阵的乘积。在这之前我需要将空间邻近与逆距离矩阵的乘积矩阵(mate)复制到每一个公司每一年对应的1*50的开店数向量旁边。而我并不知道这一步怎么做?我感觉类似merge。  因为这个乘积矩阵只因50个州(空间)而变,而不因年份和公司变化,所以想要一个类似merge 1:m stateid using ...这样的命令把矩阵merge上去,但不知道怎么实现?

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2015-12-2 13:19:28
第一次发帖就这么沉了吗~  求高手相助~
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2016-12-31 14:55:16
我生成矩阵再进行后续运算时,提示我矩阵不存在。。。不知道要怎么弄了?是不是要把生成的矩阵保存?要怎么保存呢?
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2016-12-31 14:56:30
楼主,最后你的问题解决了吗?能否分享下呢?生成空间矩阵后如何再进行回归分析呢?
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2017-4-23 11:51:13
xiangxinziji917 发表于 2016-12-31 14:56
楼主,最后你的问题解决了吗?能否分享下呢?生成空间矩阵后如何再进行回归分析呢?
最后没有用矩阵功能,取而代之用了比较繁琐的方法-通过stata的reshape功能,再不断将变量相乘,多次重复之后计算出一个新变量作为空间权重。
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2018-5-1 06:11:08
mata matsave mate *
*前必须用空格隔开
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

点击查看更多内容…
相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群