在R中有一种方法可以在回归摘要中显示因变量的平均值

发布于 2025-02-04 18:32:32 字数 3466 浏览 3 评论 0原文

我一直在使用Stargazer显示线性回归结果(DID),但似乎没有一个命令可以让我找到回归的因变量的平均值 - 与R^2或类似的统计数据一起说。

我无法链接数据 - 但这是我想要此统计数据的一个示例。

mother_employ <- felm(paid_employment ~ treat + is_post + treated_group + age_dv + age_dv^2 + marital_status + educ_levels + nkids_dv + regions + white | year |0|pidp, subset = sex_dv == 2, data)

在下面,我使用Stargazer显示回归结果 - 我试图将“平均值”放在stat Call而没有结果的情况下,

stargazer(employ_mother, title = "Mother Employment",
          font.size = "small", 
          align = TRUE,
          column.sep.width = "-15pt",keep.stat = c("adj.rsq","n"), keep = c("treat","is_post","treated_group","age_dv","age_dv^2","nkids_dv","white"), notes = "This Table Exludes Marital Status, Education Level, and Regions Covariates", type = "text")

我的输出就是这样:

Mother Employ
========================================================================================
                                         Dependent variable:                            
              --------------------------------------------------------------------------
                                           paid_employment                              
----------------------------------------------------------------------------------------
treat                                          0.082***                                 
                                               (0.013)                                  
                                                                                        
is_post1                                        0.011                                   
                                               (0.012)                                  
                                                                                        
treated_group                                 -0.352***                                 
                                               (0.010)                                  
                                                                                        
age_dv                                         0.008***                                 
                                               (0.0004)                                 
                                                                                        
nkids_dv                                      -0.061***                                 
                                               (0.004)                                  
                                                                                        
white                                          0.168***                                 
                                               (0.010)                                  
                                                                                        
----------------------------------------------------------------------------------------
Observations                                    51,528                                  
Adjusted R2                                     0.237                                   
========================================================================================
Note:                                                        *p<0.1; **p<0.05; ***p<0.01
              This Table Exludes Marital Status, Education Level, and Regions Covariates
> 

我想用r^2显示因变量的平均值吗?

I've been using stargazer to display linear regression results (DID) specifically but there doesn't seem to be a command to allow me to find the mean of the dependent variable of the regression - say along with R^2 or a similar statistic.

I can't link the data - but here's one example of where I would like this stat.

mother_employ <- felm(paid_employment ~ treat + is_post + treated_group + age_dv + age_dv^2 + marital_status + educ_levels + nkids_dv + regions + white | year |0|pidp, subset = sex_dv == 2, data)

Below I display the regression results using stargazer - I've tried to put "mean" in the keep stat call without results

stargazer(employ_mother, title = "Mother Employment",
          font.size = "small", 
          align = TRUE,
          column.sep.width = "-15pt",keep.stat = c("adj.rsq","n"), keep = c("treat","is_post","treated_group","age_dv","age_dv^2","nkids_dv","white"), notes = "This Table Exludes Marital Status, Education Level, and Regions Covariates", type = "text")

My output is such:

Mother Employ
========================================================================================
                                         Dependent variable:                            
              --------------------------------------------------------------------------
                                           paid_employment                              
----------------------------------------------------------------------------------------
treat                                          0.082***                                 
                                               (0.013)                                  
                                                                                        
is_post1                                        0.011                                   
                                               (0.012)                                  
                                                                                        
treated_group                                 -0.352***                                 
                                               (0.010)                                  
                                                                                        
age_dv                                         0.008***                                 
                                               (0.0004)                                 
                                                                                        
nkids_dv                                      -0.061***                                 
                                               (0.004)                                  
                                                                                        
white                                          0.168***                                 
                                               (0.010)                                  
                                                                                        
----------------------------------------------------------------------------------------
Observations                                    51,528                                  
Adjusted R2                                     0.237                                   
========================================================================================
Note:                                                        *p<0.1; **p<0.05; ***p<0.01
              This Table Exludes Marital Status, Education Level, and Regions Covariates
> 

I want to display the mean of the dependent variable with R^2 is this possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

玩物 2025-02-11 18:32:32

使用stargazer()的add -line参数可以使用。

library(stargazer)

model_results <- lm(mpg ~ cyl + drat, mtcars)
stargazer(model_results,
          title = "Cars",
          font.size = "small", 
          align = TRUE,
          column.sep.width = "-15pt",
          keep.stat = c("adj.rsq","n"),
          add.lines = list("Mean" = c("Mean", mean(mtcars$mpg))), 
          out = "test.txt")

或者,如果我们

Cars

========================================
                 Dependent variable:    
             ---------------------------
                         mpg            
----------------------------------------
cyl                   -2.484***         
                       (0.447)          
                                        
drat                    1.872           
                       (1.494)          
                                        
Constant              28.725***         
                       (7.592)          
                                        
----------------------------------------
Mean                  20.090625         
Observations             32             
Adjusted R2             0.722           
========================================
Note:        *p<0.1; **p<0.05; ***p<0.01

只需要在可以使用的回归中使用的值。

mean(model_results$data$mpg) # For models from lm()
mean(model_results$response) # For models from felm()

代替平均值(mtcars $ mpg)

This is possible using the add.lines argument of stargazer().

library(stargazer)

model_results <- lm(mpg ~ cyl + drat, mtcars)
stargazer(model_results,
          title = "Cars",
          font.size = "small", 
          align = TRUE,
          column.sep.width = "-15pt",
          keep.stat = c("adj.rsq","n"),
          add.lines = list("Mean" = c("Mean", mean(mtcars$mpg))), 
          out = "test.txt")

Gives us

Cars

========================================
                 Dependent variable:    
             ---------------------------
                         mpg            
----------------------------------------
cyl                   -2.484***         
                       (0.447)          
                                        
drat                    1.872           
                       (1.494)          
                                        
Constant              28.725***         
                       (7.592)          
                                        
----------------------------------------
Mean                  20.090625         
Observations             32             
Adjusted R2             0.722           
========================================
Note:        *p<0.1; **p<0.05; ***p<0.01

Alternatively, if we only want values that are used in the regression we can use.

mean(model_results$data$mpg) # For models from lm()
mean(model_results$response) # For models from felm()

In place of mean(mtcars$mpg)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文