Change order of appearance of independent variables in regression table using mtable() from the memisc...
up vote
1
down vote
favorite
I use the package memisc
for exporting my regression tables to LaTeX. I now have a three model with different independent variables (IV) and various control variables (CV) that are the same in every model.
Using
mtable("Modell 1"=lm(DV ~ IV1 + CV1 + CV2),
"Modell 2"=lm(DV ~ IV2 + CV1 + CV2),
"Modell 3"=lm(DV ~ IV3 + CV1 + CV2))
, I get a this output:
===========================================================================
Modell 1 Modell 2 Modell 3 Modell 4
---------------------------------------------------------------------------
(Intercept) -0.122 -0.112 -0.122 -0.097
(0.116) (0.115) (0.116) (0.116)
IV1 0.026 -0.083
(0.030) (0.064)
CV1 0.017 0.015 0.018 0.012
(0.019) (0.019) (0.019) (0.019)
CV2 0.064*** 0.063*** 0.066*** 0.063***
(0.016) (0.015) (0.016) (0.016)
IV3 0.076 0.196*
(0.045) (0.099)
IV4 -0.016 -0.047
(0.076) (0.078)
---------------------------------------------------------------------------
(I truncated the summary statistics). I would like IV1, IV2 and IV3 to appear first, and afterwards all the control variables. Is there any automatable solution?
r lm
add a comment |
up vote
1
down vote
favorite
I use the package memisc
for exporting my regression tables to LaTeX. I now have a three model with different independent variables (IV) and various control variables (CV) that are the same in every model.
Using
mtable("Modell 1"=lm(DV ~ IV1 + CV1 + CV2),
"Modell 2"=lm(DV ~ IV2 + CV1 + CV2),
"Modell 3"=lm(DV ~ IV3 + CV1 + CV2))
, I get a this output:
===========================================================================
Modell 1 Modell 2 Modell 3 Modell 4
---------------------------------------------------------------------------
(Intercept) -0.122 -0.112 -0.122 -0.097
(0.116) (0.115) (0.116) (0.116)
IV1 0.026 -0.083
(0.030) (0.064)
CV1 0.017 0.015 0.018 0.012
(0.019) (0.019) (0.019) (0.019)
CV2 0.064*** 0.063*** 0.066*** 0.063***
(0.016) (0.015) (0.016) (0.016)
IV3 0.076 0.196*
(0.045) (0.099)
IV4 -0.016 -0.047
(0.076) (0.078)
---------------------------------------------------------------------------
(I truncated the summary statistics). I would like IV1, IV2 and IV3 to appear first, and afterwards all the control variables. Is there any automatable solution?
r lm
stargazer
can be a good option. Do you absolutely want/need to usemtable
?
– ANG
Nov 9 at 16:01
I did all the other table inmtable
and like a consistent look (e.g. mtable aligns values by commata), so I want to continue using mtable.
– Lukas
Nov 11 at 10:16
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I use the package memisc
for exporting my regression tables to LaTeX. I now have a three model with different independent variables (IV) and various control variables (CV) that are the same in every model.
Using
mtable("Modell 1"=lm(DV ~ IV1 + CV1 + CV2),
"Modell 2"=lm(DV ~ IV2 + CV1 + CV2),
"Modell 3"=lm(DV ~ IV3 + CV1 + CV2))
, I get a this output:
===========================================================================
Modell 1 Modell 2 Modell 3 Modell 4
---------------------------------------------------------------------------
(Intercept) -0.122 -0.112 -0.122 -0.097
(0.116) (0.115) (0.116) (0.116)
IV1 0.026 -0.083
(0.030) (0.064)
CV1 0.017 0.015 0.018 0.012
(0.019) (0.019) (0.019) (0.019)
CV2 0.064*** 0.063*** 0.066*** 0.063***
(0.016) (0.015) (0.016) (0.016)
IV3 0.076 0.196*
(0.045) (0.099)
IV4 -0.016 -0.047
(0.076) (0.078)
---------------------------------------------------------------------------
(I truncated the summary statistics). I would like IV1, IV2 and IV3 to appear first, and afterwards all the control variables. Is there any automatable solution?
r lm
I use the package memisc
for exporting my regression tables to LaTeX. I now have a three model with different independent variables (IV) and various control variables (CV) that are the same in every model.
Using
mtable("Modell 1"=lm(DV ~ IV1 + CV1 + CV2),
"Modell 2"=lm(DV ~ IV2 + CV1 + CV2),
"Modell 3"=lm(DV ~ IV3 + CV1 + CV2))
, I get a this output:
===========================================================================
Modell 1 Modell 2 Modell 3 Modell 4
---------------------------------------------------------------------------
(Intercept) -0.122 -0.112 -0.122 -0.097
(0.116) (0.115) (0.116) (0.116)
IV1 0.026 -0.083
(0.030) (0.064)
CV1 0.017 0.015 0.018 0.012
(0.019) (0.019) (0.019) (0.019)
CV2 0.064*** 0.063*** 0.066*** 0.063***
(0.016) (0.015) (0.016) (0.016)
IV3 0.076 0.196*
(0.045) (0.099)
IV4 -0.016 -0.047
(0.076) (0.078)
---------------------------------------------------------------------------
(I truncated the summary statistics). I would like IV1, IV2 and IV3 to appear first, and afterwards all the control variables. Is there any automatable solution?
r lm
r lm
edited Nov 9 at 16:46
ANG
4,0472620
4,0472620
asked Nov 9 at 14:05
Lukas
5810
5810
stargazer
can be a good option. Do you absolutely want/need to usemtable
?
– ANG
Nov 9 at 16:01
I did all the other table inmtable
and like a consistent look (e.g. mtable aligns values by commata), so I want to continue using mtable.
– Lukas
Nov 11 at 10:16
add a comment |
stargazer
can be a good option. Do you absolutely want/need to usemtable
?
– ANG
Nov 9 at 16:01
I did all the other table inmtable
and like a consistent look (e.g. mtable aligns values by commata), so I want to continue using mtable.
– Lukas
Nov 11 at 10:16
stargazer
can be a good option. Do you absolutely want/need to use mtable
?– ANG
Nov 9 at 16:01
stargazer
can be a good option. Do you absolutely want/need to use mtable
?– ANG
Nov 9 at 16:01
I did all the other table in
mtable
and like a consistent look (e.g. mtable aligns values by commata), so I want to continue using mtable.– Lukas
Nov 11 at 10:16
I did all the other table in
mtable
and like a consistent look (e.g. mtable aligns values by commata), so I want to continue using mtable.– Lukas
Nov 11 at 10:16
add a comment |
1 Answer
1
active
oldest
votes
up vote
1
down vote
accepted
This is an intersiting question. Please, consider the following example.
library(memisc)
# independent variables (IV) are dpi, ddpi, log(dpi) and log(ddpi)
# control variables (CV) are pop15 and pop75
mtable("Model 1" = lm(sr ~ dpi + pop15 + pop75, LifeCycleSavings),
"Model 2" = lm(sr ~ ddpi + pop15 + pop75, LifeCycleSavings),
"Model 3" = lm(sr ~ log(dpi) + pop15 + pop75, LifeCycleSavings),
"Model 4" = lm(sr ~ log(ddpi) + pop15 + pop75, LifeCycleSavings))
# looks like mtable appends new coefficients to the list of coefficients defined in the first model
# output
Calls:
Model 1: lm(formula = sr ~ dpi + pop15 + pop75, data = LifeCycleSavings)
Model 2: lm(formula = sr ~ ddpi + pop15 + pop75, data = LifeCycleSavings)
Model 3: lm(formula = sr ~ log(dpi) + pop15 + pop75, data = LifeCycleSavings)
Model 4: lm(formula = sr ~ log(ddpi) + pop15 + pop75, data = LifeCycleSavings)
=====================================================================
Model 1 Model 2 Model 3 Model 4
---------------------------------------------------------------------
(Intercept) 31.457*** 28.125*** 36.304** 26.118***
(7.482) (7.184) (10.511) (7.416)
dpi -0.001
(0.001)
pop15 -0.492** -0.452** -0.506** -0.408**
(0.149) (0.141) (0.154) (0.144)
pop75 -1.568 -1.835 -1.649 -1.663
(1.121) (0.998) (1.110) (1.009)
ddpi 0.428*
(0.188)
log(dpi) -0.779
(1.018)
log(ddpi) 1.584*
(0.722)
---------------------------------------------------------------------
R-squared 0.274 0.337 0.271 0.332
adj. R-squared 0.227 0.293 0.223 0.288
sigma 3.939 3.767 3.948 3.780
F 5.797 7.778 5.700 7.608
p 0.002 0.000 0.002 0.000
Log-likelihood -137.410 -135.171 -137.525 -135.355
Deviance 713.767 652.606 717.054 657.424
AIC 284.821 280.341 285.050 280.709
BIC 294.381 289.902 294.610 290.269
N 50 50 50 50
=====================================================================
We now want the IV (i.e. dpi
, ddpi
, log(dpi)
and log(ddpi)
) to appear first.
Option 1
# we will define a fake model which includes all the IVs
mtables <- mtable("Model fake" = lm(sr ~ dpi + ddpi + log(dpi) + log(ddpi), LifeCycleSavings),
"Model 1" = lm(sr ~ dpi + pop15 + pop75, LifeCycleSavings),
"Model 2" = lm(sr ~ ddpi + pop15 + pop75, LifeCycleSavings),
"Model 3" = lm(sr ~ log(dpi) + pop15 + pop75, LifeCycleSavings),
"Model 4" = lm(sr ~ log(ddpi) + pop15 + pop75, LifeCycleSavings))
# we will display mtables without the fake model
mtables[2:5]
# output
Calls:
Model 1: lm(formula = sr ~ dpi + pop15 + pop75, data = LifeCycleSavings)
Model 2: lm(formula = sr ~ ddpi + pop15 + pop75, data = LifeCycleSavings)
Model 3: lm(formula = sr ~ log(dpi) + pop15 + pop75, data = LifeCycleSavings)
Model 4: lm(formula = sr ~ log(ddpi) + pop15 + pop75, data = LifeCycleSavings)
=====================================================================
Model 1 Model 2 Model 3 Model 4
---------------------------------------------------------------------
(Intercept) 31.457*** 28.125*** 36.304** 26.118***
(7.482) (7.184) (10.511) (7.416)
dpi -0.001
(0.001)
ddpi 0.428*
(0.188)
log(dpi) -0.779
(1.018)
log(ddpi) 1.584*
(0.722)
pop15 -0.492** -0.452** -0.506** -0.408**
(0.149) (0.141) (0.154) (0.144)
pop75 -1.568 -1.835 -1.649 -1.663
(1.121) (0.998) (1.110) (1.009)
---------------------------------------------------------------------
R-squared 0.274 0.337 0.271 0.332
adj. R-squared 0.227 0.293 0.223 0.288
sigma 3.939 3.767 3.948 3.780
F 5.797 7.778 5.700 7.608
p 0.002 0.000 0.002 0.000
Log-likelihood -137.410 -135.171 -137.525 -135.355
Deviance 713.767 652.606 717.054 657.424
AIC 284.821 280.341 285.050 280.709
BIC 294.381 289.902 294.610 290.269
N 50 50 50 50
=====================================================================
Option 2
# stargazer can be an option
library(stargazer)
stargazer(lm(sr ~ dpi + pop15 + pop75, LifeCycleSavings),
lm(sr ~ ddpi + pop15 + pop75, LifeCycleSavings),
lm(sr ~ log(dpi) + pop15 + pop75, LifeCycleSavings),
lm(sr ~ log(ddpi) + pop15 + pop75, LifeCycleSavings),
type = "text", column.labels = c("Model 1", "Model 2", "Model 3", "Model 4"),
model.numbers = FALSE)
# output
=====================================================================
Dependent variable:
---------------------------------------
sr
Model 1 Model 2 Model 3 Model 4
---------------------------------------------------------------------
dpi -0.001
(0.001)
ddpi 0.428**
(0.188)
log(dpi) -0.779
(1.018)
log(ddpi) 1.584**
(0.722)
pop15 -0.492*** -0.452*** -0.506*** -0.408***
(0.149) (0.141) (0.154) (0.144)
pop75 -1.568 -1.835* -1.649 -1.663
(1.121) (0.998) (1.110) (1.009)
Constant 31.457*** 28.125*** 36.304*** 26.118***
(7.482) (7.184) (10.511) (7.416)
---------------------------------------------------------------------
Observations 50 50 50 50
R2 0.274 0.337 0.271 0.332
Adjusted R2 0.227 0.293 0.223 0.288
Residual Std. Error (df = 46) 3.939 3.767 3.948 3.780
F Statistic (df = 3; 46) 5.797*** 7.778*** 5.700*** 7.608***
=====================================================================
Note: *p<0.1; **p<0.05; ***p<0.01
Solution based on your data
mtables <- mtable("Modell 0"=lm(DV ~ IV1 + IV2 + IV3),
"Modell 1"=lm(DV ~ IV1 + CV1 + CV2),
"Modell 2"=lm(DV ~ IV2 + CV1 + CV2),
"Modell 3"=lm(DV ~ IV3 + CV1 + CV2))
mtables[2:4]
# or use stargazer() as above
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
accepted
This is an intersiting question. Please, consider the following example.
library(memisc)
# independent variables (IV) are dpi, ddpi, log(dpi) and log(ddpi)
# control variables (CV) are pop15 and pop75
mtable("Model 1" = lm(sr ~ dpi + pop15 + pop75, LifeCycleSavings),
"Model 2" = lm(sr ~ ddpi + pop15 + pop75, LifeCycleSavings),
"Model 3" = lm(sr ~ log(dpi) + pop15 + pop75, LifeCycleSavings),
"Model 4" = lm(sr ~ log(ddpi) + pop15 + pop75, LifeCycleSavings))
# looks like mtable appends new coefficients to the list of coefficients defined in the first model
# output
Calls:
Model 1: lm(formula = sr ~ dpi + pop15 + pop75, data = LifeCycleSavings)
Model 2: lm(formula = sr ~ ddpi + pop15 + pop75, data = LifeCycleSavings)
Model 3: lm(formula = sr ~ log(dpi) + pop15 + pop75, data = LifeCycleSavings)
Model 4: lm(formula = sr ~ log(ddpi) + pop15 + pop75, data = LifeCycleSavings)
=====================================================================
Model 1 Model 2 Model 3 Model 4
---------------------------------------------------------------------
(Intercept) 31.457*** 28.125*** 36.304** 26.118***
(7.482) (7.184) (10.511) (7.416)
dpi -0.001
(0.001)
pop15 -0.492** -0.452** -0.506** -0.408**
(0.149) (0.141) (0.154) (0.144)
pop75 -1.568 -1.835 -1.649 -1.663
(1.121) (0.998) (1.110) (1.009)
ddpi 0.428*
(0.188)
log(dpi) -0.779
(1.018)
log(ddpi) 1.584*
(0.722)
---------------------------------------------------------------------
R-squared 0.274 0.337 0.271 0.332
adj. R-squared 0.227 0.293 0.223 0.288
sigma 3.939 3.767 3.948 3.780
F 5.797 7.778 5.700 7.608
p 0.002 0.000 0.002 0.000
Log-likelihood -137.410 -135.171 -137.525 -135.355
Deviance 713.767 652.606 717.054 657.424
AIC 284.821 280.341 285.050 280.709
BIC 294.381 289.902 294.610 290.269
N 50 50 50 50
=====================================================================
We now want the IV (i.e. dpi
, ddpi
, log(dpi)
and log(ddpi)
) to appear first.
Option 1
# we will define a fake model which includes all the IVs
mtables <- mtable("Model fake" = lm(sr ~ dpi + ddpi + log(dpi) + log(ddpi), LifeCycleSavings),
"Model 1" = lm(sr ~ dpi + pop15 + pop75, LifeCycleSavings),
"Model 2" = lm(sr ~ ddpi + pop15 + pop75, LifeCycleSavings),
"Model 3" = lm(sr ~ log(dpi) + pop15 + pop75, LifeCycleSavings),
"Model 4" = lm(sr ~ log(ddpi) + pop15 + pop75, LifeCycleSavings))
# we will display mtables without the fake model
mtables[2:5]
# output
Calls:
Model 1: lm(formula = sr ~ dpi + pop15 + pop75, data = LifeCycleSavings)
Model 2: lm(formula = sr ~ ddpi + pop15 + pop75, data = LifeCycleSavings)
Model 3: lm(formula = sr ~ log(dpi) + pop15 + pop75, data = LifeCycleSavings)
Model 4: lm(formula = sr ~ log(ddpi) + pop15 + pop75, data = LifeCycleSavings)
=====================================================================
Model 1 Model 2 Model 3 Model 4
---------------------------------------------------------------------
(Intercept) 31.457*** 28.125*** 36.304** 26.118***
(7.482) (7.184) (10.511) (7.416)
dpi -0.001
(0.001)
ddpi 0.428*
(0.188)
log(dpi) -0.779
(1.018)
log(ddpi) 1.584*
(0.722)
pop15 -0.492** -0.452** -0.506** -0.408**
(0.149) (0.141) (0.154) (0.144)
pop75 -1.568 -1.835 -1.649 -1.663
(1.121) (0.998) (1.110) (1.009)
---------------------------------------------------------------------
R-squared 0.274 0.337 0.271 0.332
adj. R-squared 0.227 0.293 0.223 0.288
sigma 3.939 3.767 3.948 3.780
F 5.797 7.778 5.700 7.608
p 0.002 0.000 0.002 0.000
Log-likelihood -137.410 -135.171 -137.525 -135.355
Deviance 713.767 652.606 717.054 657.424
AIC 284.821 280.341 285.050 280.709
BIC 294.381 289.902 294.610 290.269
N 50 50 50 50
=====================================================================
Option 2
# stargazer can be an option
library(stargazer)
stargazer(lm(sr ~ dpi + pop15 + pop75, LifeCycleSavings),
lm(sr ~ ddpi + pop15 + pop75, LifeCycleSavings),
lm(sr ~ log(dpi) + pop15 + pop75, LifeCycleSavings),
lm(sr ~ log(ddpi) + pop15 + pop75, LifeCycleSavings),
type = "text", column.labels = c("Model 1", "Model 2", "Model 3", "Model 4"),
model.numbers = FALSE)
# output
=====================================================================
Dependent variable:
---------------------------------------
sr
Model 1 Model 2 Model 3 Model 4
---------------------------------------------------------------------
dpi -0.001
(0.001)
ddpi 0.428**
(0.188)
log(dpi) -0.779
(1.018)
log(ddpi) 1.584**
(0.722)
pop15 -0.492*** -0.452*** -0.506*** -0.408***
(0.149) (0.141) (0.154) (0.144)
pop75 -1.568 -1.835* -1.649 -1.663
(1.121) (0.998) (1.110) (1.009)
Constant 31.457*** 28.125*** 36.304*** 26.118***
(7.482) (7.184) (10.511) (7.416)
---------------------------------------------------------------------
Observations 50 50 50 50
R2 0.274 0.337 0.271 0.332
Adjusted R2 0.227 0.293 0.223 0.288
Residual Std. Error (df = 46) 3.939 3.767 3.948 3.780
F Statistic (df = 3; 46) 5.797*** 7.778*** 5.700*** 7.608***
=====================================================================
Note: *p<0.1; **p<0.05; ***p<0.01
Solution based on your data
mtables <- mtable("Modell 0"=lm(DV ~ IV1 + IV2 + IV3),
"Modell 1"=lm(DV ~ IV1 + CV1 + CV2),
"Modell 2"=lm(DV ~ IV2 + CV1 + CV2),
"Modell 3"=lm(DV ~ IV3 + CV1 + CV2))
mtables[2:4]
# or use stargazer() as above
add a comment |
up vote
1
down vote
accepted
This is an intersiting question. Please, consider the following example.
library(memisc)
# independent variables (IV) are dpi, ddpi, log(dpi) and log(ddpi)
# control variables (CV) are pop15 and pop75
mtable("Model 1" = lm(sr ~ dpi + pop15 + pop75, LifeCycleSavings),
"Model 2" = lm(sr ~ ddpi + pop15 + pop75, LifeCycleSavings),
"Model 3" = lm(sr ~ log(dpi) + pop15 + pop75, LifeCycleSavings),
"Model 4" = lm(sr ~ log(ddpi) + pop15 + pop75, LifeCycleSavings))
# looks like mtable appends new coefficients to the list of coefficients defined in the first model
# output
Calls:
Model 1: lm(formula = sr ~ dpi + pop15 + pop75, data = LifeCycleSavings)
Model 2: lm(formula = sr ~ ddpi + pop15 + pop75, data = LifeCycleSavings)
Model 3: lm(formula = sr ~ log(dpi) + pop15 + pop75, data = LifeCycleSavings)
Model 4: lm(formula = sr ~ log(ddpi) + pop15 + pop75, data = LifeCycleSavings)
=====================================================================
Model 1 Model 2 Model 3 Model 4
---------------------------------------------------------------------
(Intercept) 31.457*** 28.125*** 36.304** 26.118***
(7.482) (7.184) (10.511) (7.416)
dpi -0.001
(0.001)
pop15 -0.492** -0.452** -0.506** -0.408**
(0.149) (0.141) (0.154) (0.144)
pop75 -1.568 -1.835 -1.649 -1.663
(1.121) (0.998) (1.110) (1.009)
ddpi 0.428*
(0.188)
log(dpi) -0.779
(1.018)
log(ddpi) 1.584*
(0.722)
---------------------------------------------------------------------
R-squared 0.274 0.337 0.271 0.332
adj. R-squared 0.227 0.293 0.223 0.288
sigma 3.939 3.767 3.948 3.780
F 5.797 7.778 5.700 7.608
p 0.002 0.000 0.002 0.000
Log-likelihood -137.410 -135.171 -137.525 -135.355
Deviance 713.767 652.606 717.054 657.424
AIC 284.821 280.341 285.050 280.709
BIC 294.381 289.902 294.610 290.269
N 50 50 50 50
=====================================================================
We now want the IV (i.e. dpi
, ddpi
, log(dpi)
and log(ddpi)
) to appear first.
Option 1
# we will define a fake model which includes all the IVs
mtables <- mtable("Model fake" = lm(sr ~ dpi + ddpi + log(dpi) + log(ddpi), LifeCycleSavings),
"Model 1" = lm(sr ~ dpi + pop15 + pop75, LifeCycleSavings),
"Model 2" = lm(sr ~ ddpi + pop15 + pop75, LifeCycleSavings),
"Model 3" = lm(sr ~ log(dpi) + pop15 + pop75, LifeCycleSavings),
"Model 4" = lm(sr ~ log(ddpi) + pop15 + pop75, LifeCycleSavings))
# we will display mtables without the fake model
mtables[2:5]
# output
Calls:
Model 1: lm(formula = sr ~ dpi + pop15 + pop75, data = LifeCycleSavings)
Model 2: lm(formula = sr ~ ddpi + pop15 + pop75, data = LifeCycleSavings)
Model 3: lm(formula = sr ~ log(dpi) + pop15 + pop75, data = LifeCycleSavings)
Model 4: lm(formula = sr ~ log(ddpi) + pop15 + pop75, data = LifeCycleSavings)
=====================================================================
Model 1 Model 2 Model 3 Model 4
---------------------------------------------------------------------
(Intercept) 31.457*** 28.125*** 36.304** 26.118***
(7.482) (7.184) (10.511) (7.416)
dpi -0.001
(0.001)
ddpi 0.428*
(0.188)
log(dpi) -0.779
(1.018)
log(ddpi) 1.584*
(0.722)
pop15 -0.492** -0.452** -0.506** -0.408**
(0.149) (0.141) (0.154) (0.144)
pop75 -1.568 -1.835 -1.649 -1.663
(1.121) (0.998) (1.110) (1.009)
---------------------------------------------------------------------
R-squared 0.274 0.337 0.271 0.332
adj. R-squared 0.227 0.293 0.223 0.288
sigma 3.939 3.767 3.948 3.780
F 5.797 7.778 5.700 7.608
p 0.002 0.000 0.002 0.000
Log-likelihood -137.410 -135.171 -137.525 -135.355
Deviance 713.767 652.606 717.054 657.424
AIC 284.821 280.341 285.050 280.709
BIC 294.381 289.902 294.610 290.269
N 50 50 50 50
=====================================================================
Option 2
# stargazer can be an option
library(stargazer)
stargazer(lm(sr ~ dpi + pop15 + pop75, LifeCycleSavings),
lm(sr ~ ddpi + pop15 + pop75, LifeCycleSavings),
lm(sr ~ log(dpi) + pop15 + pop75, LifeCycleSavings),
lm(sr ~ log(ddpi) + pop15 + pop75, LifeCycleSavings),
type = "text", column.labels = c("Model 1", "Model 2", "Model 3", "Model 4"),
model.numbers = FALSE)
# output
=====================================================================
Dependent variable:
---------------------------------------
sr
Model 1 Model 2 Model 3 Model 4
---------------------------------------------------------------------
dpi -0.001
(0.001)
ddpi 0.428**
(0.188)
log(dpi) -0.779
(1.018)
log(ddpi) 1.584**
(0.722)
pop15 -0.492*** -0.452*** -0.506*** -0.408***
(0.149) (0.141) (0.154) (0.144)
pop75 -1.568 -1.835* -1.649 -1.663
(1.121) (0.998) (1.110) (1.009)
Constant 31.457*** 28.125*** 36.304*** 26.118***
(7.482) (7.184) (10.511) (7.416)
---------------------------------------------------------------------
Observations 50 50 50 50
R2 0.274 0.337 0.271 0.332
Adjusted R2 0.227 0.293 0.223 0.288
Residual Std. Error (df = 46) 3.939 3.767 3.948 3.780
F Statistic (df = 3; 46) 5.797*** 7.778*** 5.700*** 7.608***
=====================================================================
Note: *p<0.1; **p<0.05; ***p<0.01
Solution based on your data
mtables <- mtable("Modell 0"=lm(DV ~ IV1 + IV2 + IV3),
"Modell 1"=lm(DV ~ IV1 + CV1 + CV2),
"Modell 2"=lm(DV ~ IV2 + CV1 + CV2),
"Modell 3"=lm(DV ~ IV3 + CV1 + CV2))
mtables[2:4]
# or use stargazer() as above
add a comment |
up vote
1
down vote
accepted
up vote
1
down vote
accepted
This is an intersiting question. Please, consider the following example.
library(memisc)
# independent variables (IV) are dpi, ddpi, log(dpi) and log(ddpi)
# control variables (CV) are pop15 and pop75
mtable("Model 1" = lm(sr ~ dpi + pop15 + pop75, LifeCycleSavings),
"Model 2" = lm(sr ~ ddpi + pop15 + pop75, LifeCycleSavings),
"Model 3" = lm(sr ~ log(dpi) + pop15 + pop75, LifeCycleSavings),
"Model 4" = lm(sr ~ log(ddpi) + pop15 + pop75, LifeCycleSavings))
# looks like mtable appends new coefficients to the list of coefficients defined in the first model
# output
Calls:
Model 1: lm(formula = sr ~ dpi + pop15 + pop75, data = LifeCycleSavings)
Model 2: lm(formula = sr ~ ddpi + pop15 + pop75, data = LifeCycleSavings)
Model 3: lm(formula = sr ~ log(dpi) + pop15 + pop75, data = LifeCycleSavings)
Model 4: lm(formula = sr ~ log(ddpi) + pop15 + pop75, data = LifeCycleSavings)
=====================================================================
Model 1 Model 2 Model 3 Model 4
---------------------------------------------------------------------
(Intercept) 31.457*** 28.125*** 36.304** 26.118***
(7.482) (7.184) (10.511) (7.416)
dpi -0.001
(0.001)
pop15 -0.492** -0.452** -0.506** -0.408**
(0.149) (0.141) (0.154) (0.144)
pop75 -1.568 -1.835 -1.649 -1.663
(1.121) (0.998) (1.110) (1.009)
ddpi 0.428*
(0.188)
log(dpi) -0.779
(1.018)
log(ddpi) 1.584*
(0.722)
---------------------------------------------------------------------
R-squared 0.274 0.337 0.271 0.332
adj. R-squared 0.227 0.293 0.223 0.288
sigma 3.939 3.767 3.948 3.780
F 5.797 7.778 5.700 7.608
p 0.002 0.000 0.002 0.000
Log-likelihood -137.410 -135.171 -137.525 -135.355
Deviance 713.767 652.606 717.054 657.424
AIC 284.821 280.341 285.050 280.709
BIC 294.381 289.902 294.610 290.269
N 50 50 50 50
=====================================================================
We now want the IV (i.e. dpi
, ddpi
, log(dpi)
and log(ddpi)
) to appear first.
Option 1
# we will define a fake model which includes all the IVs
mtables <- mtable("Model fake" = lm(sr ~ dpi + ddpi + log(dpi) + log(ddpi), LifeCycleSavings),
"Model 1" = lm(sr ~ dpi + pop15 + pop75, LifeCycleSavings),
"Model 2" = lm(sr ~ ddpi + pop15 + pop75, LifeCycleSavings),
"Model 3" = lm(sr ~ log(dpi) + pop15 + pop75, LifeCycleSavings),
"Model 4" = lm(sr ~ log(ddpi) + pop15 + pop75, LifeCycleSavings))
# we will display mtables without the fake model
mtables[2:5]
# output
Calls:
Model 1: lm(formula = sr ~ dpi + pop15 + pop75, data = LifeCycleSavings)
Model 2: lm(formula = sr ~ ddpi + pop15 + pop75, data = LifeCycleSavings)
Model 3: lm(formula = sr ~ log(dpi) + pop15 + pop75, data = LifeCycleSavings)
Model 4: lm(formula = sr ~ log(ddpi) + pop15 + pop75, data = LifeCycleSavings)
=====================================================================
Model 1 Model 2 Model 3 Model 4
---------------------------------------------------------------------
(Intercept) 31.457*** 28.125*** 36.304** 26.118***
(7.482) (7.184) (10.511) (7.416)
dpi -0.001
(0.001)
ddpi 0.428*
(0.188)
log(dpi) -0.779
(1.018)
log(ddpi) 1.584*
(0.722)
pop15 -0.492** -0.452** -0.506** -0.408**
(0.149) (0.141) (0.154) (0.144)
pop75 -1.568 -1.835 -1.649 -1.663
(1.121) (0.998) (1.110) (1.009)
---------------------------------------------------------------------
R-squared 0.274 0.337 0.271 0.332
adj. R-squared 0.227 0.293 0.223 0.288
sigma 3.939 3.767 3.948 3.780
F 5.797 7.778 5.700 7.608
p 0.002 0.000 0.002 0.000
Log-likelihood -137.410 -135.171 -137.525 -135.355
Deviance 713.767 652.606 717.054 657.424
AIC 284.821 280.341 285.050 280.709
BIC 294.381 289.902 294.610 290.269
N 50 50 50 50
=====================================================================
Option 2
# stargazer can be an option
library(stargazer)
stargazer(lm(sr ~ dpi + pop15 + pop75, LifeCycleSavings),
lm(sr ~ ddpi + pop15 + pop75, LifeCycleSavings),
lm(sr ~ log(dpi) + pop15 + pop75, LifeCycleSavings),
lm(sr ~ log(ddpi) + pop15 + pop75, LifeCycleSavings),
type = "text", column.labels = c("Model 1", "Model 2", "Model 3", "Model 4"),
model.numbers = FALSE)
# output
=====================================================================
Dependent variable:
---------------------------------------
sr
Model 1 Model 2 Model 3 Model 4
---------------------------------------------------------------------
dpi -0.001
(0.001)
ddpi 0.428**
(0.188)
log(dpi) -0.779
(1.018)
log(ddpi) 1.584**
(0.722)
pop15 -0.492*** -0.452*** -0.506*** -0.408***
(0.149) (0.141) (0.154) (0.144)
pop75 -1.568 -1.835* -1.649 -1.663
(1.121) (0.998) (1.110) (1.009)
Constant 31.457*** 28.125*** 36.304*** 26.118***
(7.482) (7.184) (10.511) (7.416)
---------------------------------------------------------------------
Observations 50 50 50 50
R2 0.274 0.337 0.271 0.332
Adjusted R2 0.227 0.293 0.223 0.288
Residual Std. Error (df = 46) 3.939 3.767 3.948 3.780
F Statistic (df = 3; 46) 5.797*** 7.778*** 5.700*** 7.608***
=====================================================================
Note: *p<0.1; **p<0.05; ***p<0.01
Solution based on your data
mtables <- mtable("Modell 0"=lm(DV ~ IV1 + IV2 + IV3),
"Modell 1"=lm(DV ~ IV1 + CV1 + CV2),
"Modell 2"=lm(DV ~ IV2 + CV1 + CV2),
"Modell 3"=lm(DV ~ IV3 + CV1 + CV2))
mtables[2:4]
# or use stargazer() as above
This is an intersiting question. Please, consider the following example.
library(memisc)
# independent variables (IV) are dpi, ddpi, log(dpi) and log(ddpi)
# control variables (CV) are pop15 and pop75
mtable("Model 1" = lm(sr ~ dpi + pop15 + pop75, LifeCycleSavings),
"Model 2" = lm(sr ~ ddpi + pop15 + pop75, LifeCycleSavings),
"Model 3" = lm(sr ~ log(dpi) + pop15 + pop75, LifeCycleSavings),
"Model 4" = lm(sr ~ log(ddpi) + pop15 + pop75, LifeCycleSavings))
# looks like mtable appends new coefficients to the list of coefficients defined in the first model
# output
Calls:
Model 1: lm(formula = sr ~ dpi + pop15 + pop75, data = LifeCycleSavings)
Model 2: lm(formula = sr ~ ddpi + pop15 + pop75, data = LifeCycleSavings)
Model 3: lm(formula = sr ~ log(dpi) + pop15 + pop75, data = LifeCycleSavings)
Model 4: lm(formula = sr ~ log(ddpi) + pop15 + pop75, data = LifeCycleSavings)
=====================================================================
Model 1 Model 2 Model 3 Model 4
---------------------------------------------------------------------
(Intercept) 31.457*** 28.125*** 36.304** 26.118***
(7.482) (7.184) (10.511) (7.416)
dpi -0.001
(0.001)
pop15 -0.492** -0.452** -0.506** -0.408**
(0.149) (0.141) (0.154) (0.144)
pop75 -1.568 -1.835 -1.649 -1.663
(1.121) (0.998) (1.110) (1.009)
ddpi 0.428*
(0.188)
log(dpi) -0.779
(1.018)
log(ddpi) 1.584*
(0.722)
---------------------------------------------------------------------
R-squared 0.274 0.337 0.271 0.332
adj. R-squared 0.227 0.293 0.223 0.288
sigma 3.939 3.767 3.948 3.780
F 5.797 7.778 5.700 7.608
p 0.002 0.000 0.002 0.000
Log-likelihood -137.410 -135.171 -137.525 -135.355
Deviance 713.767 652.606 717.054 657.424
AIC 284.821 280.341 285.050 280.709
BIC 294.381 289.902 294.610 290.269
N 50 50 50 50
=====================================================================
We now want the IV (i.e. dpi
, ddpi
, log(dpi)
and log(ddpi)
) to appear first.
Option 1
# we will define a fake model which includes all the IVs
mtables <- mtable("Model fake" = lm(sr ~ dpi + ddpi + log(dpi) + log(ddpi), LifeCycleSavings),
"Model 1" = lm(sr ~ dpi + pop15 + pop75, LifeCycleSavings),
"Model 2" = lm(sr ~ ddpi + pop15 + pop75, LifeCycleSavings),
"Model 3" = lm(sr ~ log(dpi) + pop15 + pop75, LifeCycleSavings),
"Model 4" = lm(sr ~ log(ddpi) + pop15 + pop75, LifeCycleSavings))
# we will display mtables without the fake model
mtables[2:5]
# output
Calls:
Model 1: lm(formula = sr ~ dpi + pop15 + pop75, data = LifeCycleSavings)
Model 2: lm(formula = sr ~ ddpi + pop15 + pop75, data = LifeCycleSavings)
Model 3: lm(formula = sr ~ log(dpi) + pop15 + pop75, data = LifeCycleSavings)
Model 4: lm(formula = sr ~ log(ddpi) + pop15 + pop75, data = LifeCycleSavings)
=====================================================================
Model 1 Model 2 Model 3 Model 4
---------------------------------------------------------------------
(Intercept) 31.457*** 28.125*** 36.304** 26.118***
(7.482) (7.184) (10.511) (7.416)
dpi -0.001
(0.001)
ddpi 0.428*
(0.188)
log(dpi) -0.779
(1.018)
log(ddpi) 1.584*
(0.722)
pop15 -0.492** -0.452** -0.506** -0.408**
(0.149) (0.141) (0.154) (0.144)
pop75 -1.568 -1.835 -1.649 -1.663
(1.121) (0.998) (1.110) (1.009)
---------------------------------------------------------------------
R-squared 0.274 0.337 0.271 0.332
adj. R-squared 0.227 0.293 0.223 0.288
sigma 3.939 3.767 3.948 3.780
F 5.797 7.778 5.700 7.608
p 0.002 0.000 0.002 0.000
Log-likelihood -137.410 -135.171 -137.525 -135.355
Deviance 713.767 652.606 717.054 657.424
AIC 284.821 280.341 285.050 280.709
BIC 294.381 289.902 294.610 290.269
N 50 50 50 50
=====================================================================
Option 2
# stargazer can be an option
library(stargazer)
stargazer(lm(sr ~ dpi + pop15 + pop75, LifeCycleSavings),
lm(sr ~ ddpi + pop15 + pop75, LifeCycleSavings),
lm(sr ~ log(dpi) + pop15 + pop75, LifeCycleSavings),
lm(sr ~ log(ddpi) + pop15 + pop75, LifeCycleSavings),
type = "text", column.labels = c("Model 1", "Model 2", "Model 3", "Model 4"),
model.numbers = FALSE)
# output
=====================================================================
Dependent variable:
---------------------------------------
sr
Model 1 Model 2 Model 3 Model 4
---------------------------------------------------------------------
dpi -0.001
(0.001)
ddpi 0.428**
(0.188)
log(dpi) -0.779
(1.018)
log(ddpi) 1.584**
(0.722)
pop15 -0.492*** -0.452*** -0.506*** -0.408***
(0.149) (0.141) (0.154) (0.144)
pop75 -1.568 -1.835* -1.649 -1.663
(1.121) (0.998) (1.110) (1.009)
Constant 31.457*** 28.125*** 36.304*** 26.118***
(7.482) (7.184) (10.511) (7.416)
---------------------------------------------------------------------
Observations 50 50 50 50
R2 0.274 0.337 0.271 0.332
Adjusted R2 0.227 0.293 0.223 0.288
Residual Std. Error (df = 46) 3.939 3.767 3.948 3.780
F Statistic (df = 3; 46) 5.797*** 7.778*** 5.700*** 7.608***
=====================================================================
Note: *p<0.1; **p<0.05; ***p<0.01
Solution based on your data
mtables <- mtable("Modell 0"=lm(DV ~ IV1 + IV2 + IV3),
"Modell 1"=lm(DV ~ IV1 + CV1 + CV2),
"Modell 2"=lm(DV ~ IV2 + CV1 + CV2),
"Modell 3"=lm(DV ~ IV3 + CV1 + CV2))
mtables[2:4]
# or use stargazer() as above
edited Nov 10 at 18:43
answered Nov 9 at 16:44
ANG
4,0472620
4,0472620
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53227227%2fchange-order-of-appearance-of-independent-variables-in-regression-table-using-mt%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
stargazer
can be a good option. Do you absolutely want/need to usemtable
?– ANG
Nov 9 at 16:01
I did all the other table in
mtable
and like a consistent look (e.g. mtable aligns values by commata), so I want to continue using mtable.– Lukas
Nov 11 at 10:16