Stata&x27;s带两组边距的estout

Stata&x27;s带两组边距的estout,stata,Stata,假设我有一个这样的模型: webuse nlswork poisson hours i.union##c.tenure, robust margins union, dydx(tenure) margins rb1.union, dydx(tenure) 我想用Ben Jann的-estout-将这两个AMEs叠加在AMEs的差异之上。不幸的是,您需要发布estout的边距结果,这会干扰第二个边距命令 这有什么办法吗 有一段时间我一直在网上交叉发布,但没有得到回复。我从来没有使用过-estou

假设我有一个这样的模型:

webuse nlswork
poisson hours i.union##c.tenure, robust
margins union, dydx(tenure)
margins rb1.union, dydx(tenure)
我想用Ben Jann的-estout-将这两个AMEs叠加在AMEs的差异之上。不幸的是,您需要发布estout的边距结果,这会干扰第二个边距命令

这有什么办法吗


有一段时间我一直在网上交叉发布,但没有得到回复。

我从来没有使用过-estout-,但也许这会给你一个开始

 webuse nlswork
 poisson hours i.union##c.tenure, robust
 estimates store m0
 
 margins union, dydx(tenure) post
 estimates store m1

 estimates restore m0

 margins rb1.union, dydx(tenure) post
 estimates store m2
工作原理:
margins
需要访问原始命令的结果,本例中为
poisson
。由于
margins
本身不会留下估计结果,因此,如果您在不使用
post
的情况下运行
margins
,并且可以在一行中使用多个
margins
命令,则原始结果仍然可用。但是,如果将
post
选项添加到第一个
margins
命令,则新发布的结果将替换内存中的结果。在这种情况下,第二个
页边距
将抱怨

页边距不能用于其自己发布的结果

因此,解决方案是用原始估计结果显示第二个
边距
,这正是
估计恢复
的目的

更新
r(表)
包含
页边距的所有结果,并命名列。下面是Roberto的堆叠解决方案的一个版本,它利用了以下特性:

use nlswork, clear,
poisson hours i.union##c.tenure, robust

margins union, dydx(tenure)
matrix list r(table)
matrix m1 = r(table)
matrix  m11 = m1["b".."se", 1...]'
matrix m12 = m1["ll".."ul",1...]'
matrix first = m11,m12

margins rb1.union, dydx(tenure)
matrix m2 = r(table)
matrix m21 = m2["b".."se", 1...]'
matrix m22 = m2["ll".."ul",1...]'
matrix second = m21,m22
matrix rownames second = tenure:diff

matrix RESULTS = first \ second
estout matrix(RESULTS)

我从未使用过-estout-,但也许这会给你一个开始

 webuse nlswork
 poisson hours i.union##c.tenure, robust
 estimates store m0
 
 margins union, dydx(tenure) post
 estimates store m1

 estimates restore m0

 margins rb1.union, dydx(tenure) post
 estimates store m2
工作原理:
margins
需要访问原始命令的结果,本例中为
poisson
。由于
margins
本身不会留下估计结果,因此,如果您在不使用
post
的情况下运行
margins
,并且可以在一行中使用多个
margins
命令,则原始结果仍然可用。但是,如果将
post
选项添加到第一个
margins
命令,则新发布的结果将替换内存中的结果。在这种情况下,第二个
页边距
将抱怨

页边距不能用于其自己发布的结果

因此,解决方案是用原始估计结果显示第二个
边距
,这正是
估计恢复
的目的

更新
r(表)
包含
页边距的所有结果,并命名列。下面是Roberto的堆叠解决方案的一个版本,它利用了以下特性:

use nlswork, clear,
poisson hours i.union##c.tenure, robust

margins union, dydx(tenure)
matrix list r(table)
matrix m1 = r(table)
matrix  m11 = m1["b".."se", 1...]'
matrix m12 = m1["ll".."ul",1...]'
matrix first = m11,m12

margins rb1.union, dydx(tenure)
matrix m2 = r(table)
matrix m21 = m2["b".."se", 1...]'
matrix m22 = m2["ll".."ul",1...]'
matrix second = m21,m22
matrix rownames second = tenure:diff

matrix RESULTS = first \ second
estout matrix(RESULTS)

estout
采用矩阵,因此您可以尝试:

webuse nlswork, clear

poisson hours i.union##c.tenure, robust
margins union, dydx(tenure)

matrix first = r(b)
matrix list first

margins rb1.union, dydx(tenure)

matrix second = r(b)
matrix list second

*-----

matrix b = first[1,1] ,  first[1,2] \ second[1,1] ,  .

estout matrix(b)
当然,你需要改进结果

更新 有一个例子,Ben Jann(
estout
的作者)澄清说,单独使用
estout
不可能将多个存储结果堆叠到一列中。他的解决方案包括一个
程序
,该程序将处理矩阵和列/行名称的结果合并在一起

对于您提供的示例,类似于以下内容的内容适用:

webuse nlswork, clear

poisson hours i.union##c.tenure, robust

// first margin
margins union, dydx(tenure)
matrix first = r(b)

// second margin
margins rb1.union, dydx(tenure)
matrix second = r(b)
matrix rownames second = tenure:diff

// put together
matrix c = first' \ second

estout matrix(c)

(线程有点旧,因此我不确定当前是否已更新
estout
以执行此操作。)

estout
获取矩阵,因此您可以尝试:

webuse nlswork, clear

poisson hours i.union##c.tenure, robust
margins union, dydx(tenure)

matrix first = r(b)
matrix list first

margins rb1.union, dydx(tenure)

matrix second = r(b)
matrix list second

*-----

matrix b = first[1,1] ,  first[1,2] \ second[1,1] ,  .

estout matrix(b)
当然,你需要改进结果

更新 有一个例子,Ben Jann(
estout
的作者)澄清说,单独使用
estout
不可能将多个存储结果堆叠到一列中。他的解决方案包括一个
程序
,该程序将处理矩阵和列/行名称的结果合并在一起

对于您提供的示例,类似于以下内容的内容适用:

webuse nlswork, clear

poisson hours i.union##c.tenure, robust

// first margin
margins union, dydx(tenure)
matrix first = r(b)

// second margin
margins rb1.union, dydx(tenure)
matrix second = r(b)
matrix rownames second = tenure:diff

// put together
matrix c = first' \ second

estout matrix(c)

(线程有点旧,所以我不确定当前是否更新了
estout
来执行此操作。)

这似乎是一个很好的解决方案。我想在一列中的第二列之上堆叠第一个线程。有什么方法可以做到这一点吗?它们可以堆叠起来,再加上一些额外的工作。我提供了一个更新我的答案。这似乎是一个很好的解决方案。我想在一列中的第二列的顶部堆叠第一个。有什么方法可以做到这一点吗?它们可以堆叠起来,再加上一些额外的工作。我更新了我的答案。非常好,罗伯托!我在更新我自己的答案时“润色”了这个解决方案。我从
r(表)
中提取,而不是像本那样从
e(b)
e(V)
中提取;这不仅得到了更多的统计数据,而且在某种程度上简化了名字问题。非常好,罗伯托!我在更新我自己的答案时“润色”了这个解决方案。我从
r(表)
中提取,而不是像本那样从
e(b)
e(V)
中提取;这不仅获得了更多的统计数据,而且在某种程度上简化了名称问题。