--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
name: <unnamed>
log: C:\Users\fan\Stata4Econ\reglin\discrete\fs_reg_d_interact.smcl
log type: smcl
opened on: 16 Aug 2019, 19:02:11
. log on
(log already on)
.
. ///--- Load Data
> set more off
. sysuse auto, clear
(1978 Automobile Data)
.
. tab rep78
Repair |
Record 1978 | Freq. Percent Cum.
------------+-----------------------------------
1 | 2 2.90 2.90
2 | 8 11.59 14.49
3 | 30 43.48 57.97
4 | 18 26.09 84.06
5 | 11 15.94 100.00
------------+-----------------------------------
Total | 69 100.00
. tab foreign
Car type | Freq. Percent Cum.
------------+-----------------------------------
Domestic | 52 70.27 70.27
Foreign | 22 29.73 100.00
------------+-----------------------------------
Total | 74 100.00
.
. * 1. Same regression for two Subgroups
. eststo clear
. eststo, title(dom): regress weight ib3.rep78 if foreign == 0
Source | SS df MS Number of obs = 48
-------------+---------------------------------- F(4, 43) = 2.73
Model | 4501656.94 4 1125414.24 Prob > F = 0.0414
Residual | 17746209.7 43 412702.552 R-squared = 0.2023
-------------+---------------------------------- Adj R-squared = 0.1281
Total | 22247866.7 47 473358.865 Root MSE = 642.42
------------------------------------------------------------------------------
weight | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
rep78 |
1 | -342.2222 470.7829 -0.73 0.471 -1291.646 607.202
2 | -88.47222 258.5983 -0.34 0.734 -609.9855 433.041
4 | 90 247.2673 0.36 0.718 -408.662 588.662
5 | -1482.222 470.7829 -3.15 0.003 -2431.646 -532.798
|
_cons | 3442.222 123.6337 27.84 0.000 3192.891 3691.553
------------------------------------------------------------------------------
(est1 stored)
. eststo, title(foreign): regress weight ib3.rep78 if foreign == 1
Source | SS df MS Number of obs = 21
-------------+---------------------------------- F(2, 18) = 1.58
Model | 396711.111 2 198355.556 Prob > F = 0.2338
Residual | 2263555.56 18 125753.086 R-squared = 0.1491
-------------+---------------------------------- Adj R-squared = 0.0546
Total | 2660266.67 20 133013.333 Root MSE = 354.62
------------------------------------------------------------------------------
weight | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------
rep78 |
4 | 197.7778 236.4112 0.84 0.414 -298.9037 694.4593
5 | 393.3333 236.4112 1.66 0.113 -103.3482 890.0149
|
_cons | 2010 204.7381 9.82 0.000 1579.861 2440.139
------------------------------------------------------------------------------
(est2 stored)
. esttab, mtitle title("Foreign or Domestic")
Foreign or Domestic
--------------------------------------------
(1) (2)
dom foreign
--------------------------------------------
1.rep78 -342.2
(-0.73)
2.rep78 -88.47
(-0.34)
3.rep78 0 0
(.) (.)
4.rep78 90.00 197.8
(0.36) (0.84)
5.rep78 -1482.2** 393.3
(-3.15) (1.66)
_cons 3442.2*** 2010.0***
(27.84) (9.82)
--------------------------------------------
N 48 21
--------------------------------------------
t statistics in parentheses
* p<0.05, ** p<0.01, *** p<0.001
.
. * 2. Show alll subgroup coefficients in one regression
. capture drop domestic
. recode foreign ///
> (0 = 1 "domestic") ///1
> (1 = 0 "foreign") ///
> (else = .) ///
> , ///
> gen(domestic)
(74 differences between foreign and domestic)
. tab domestic foreign
RECODE of |
foreign | Car type
(Car type) | Domestic Foreign | Total
-----------+----------------------+----------
foreign | 0 22 | 22
domestic | 52 0 | 52
-----------+----------------------+----------
Total | 52 22 | 74
.
. * using factor for binary
. eststo clear
. eststo, title(both): quietly regress ///
> weight ///
> ib0.foreign ib0.domestic ///
> ib3.rep78#ib0.foreign ///
> ib3.rep78#ib0.domestic ///
> , noc
(est1 stored)
. esttab, mtitle title("Foreign or Domestic")
Foreign or Domestic
----------------------------
(1)
both
----------------------------
0.foreign 0
(.)
1.foreign 2010.0***
(6.08)
0.domestic 0
(.)
1.domestic 3442.2***
(31.23)
1.rep78#0.~n -342.2
(-0.82)
1.rep78#1.~n 0
(.)
2.rep78#0.~n -88.47
(-0.38)
2.rep78#1.~n 0
(.)
3.rep78#0.~n 0
(.)
3.rep78#1.~n 0
(.)
4.rep78#0.~n 90.00
(0.41)
4.rep78#1.~n 197.8
(0.52)
5.rep78#0.~n -1482.2***
(-3.53)
5.rep78#1.~n 393.3
(1.03)
1.rep78#0.~c 0
(.)
1.rep78#1.~c 0
(.)
2.rep78#0.~c 0
(.)
2.rep78#1.~c 0
(.)
3.rep78#0.~c 0
(.)
3.rep78#1.~c 0
(.)
4.rep78#0.~c 0
(.)
4.rep78#1.~c 0
(.)
5.rep78#0.~c 0
(.)
5.rep78#1.~c 0
(.)
----------------------------
N 69
----------------------------
t statistics in parentheses
* p<0.05, ** p<0.01, *** p<0.001
.
. * Streamlined
. eststo clear
. regress ///
> weight ///
> ib0.foreign ib0.domestic ///
> ib3.rep78#ib0.foreign ///
> , noc
note: 1.rep78#1.foreign identifies no observations in the sample
note: 2.rep78#1.foreign identifies no observations in the sample
Source | SS df MS Number of obs = 69
-------------+---------------------------------- F(8, 61) = 250.38
Model | 657066735 8 82133341.8 Prob > F = 0.0000
Residual | 20009765.3 61 328028.939 R-squared = 0.9704
-------------+---------------------------------- Adj R-squared = 0.9666
Total | 677076500 69 9812702.9 Root MSE = 572.74
-------------------------------------------------------------------------------
weight | Coef. Std. Err. t P>|t| [95% Conf. Interval]
--------------+----------------------------------------------------------------
foreign |
Foreign | 2010 330.6705 6.08 0.000 1348.783 2671.217
|
domestic |
domestic | 3442.222 110.2235 31.23 0.000 3221.817 3662.628
|
rep78#foreign |
1#Domestic | -342.2222 419.7186 -0.82 0.418 -1181.501 497.057
1#Foreign | 0 (empty)
2#Domestic | -88.47222 230.549 -0.38 0.703 -549.4834 372.539
2#Foreign | 0 (empty)
4#Domestic | 90 220.447 0.41 0.685 -350.811 530.811
4#Foreign | 197.7778 381.8254 0.52 0.606 -565.7293 961.2849
5#Domestic | -1482.222 419.7186 -3.53 0.001 -2321.501 -642.943
5#Foreign | 393.3333 381.8254 1.03 0.307 -370.1738 1156.84
-------------------------------------------------------------------------------
. esttab, mtitle title("Foreign or Domestic")
Foreign or Domestic
----------------------------
(1)
.
----------------------------
0.foreign 0
(.)
1.foreign 2010.0***
(6.08)
0.domestic 0
(.)
1.domestic 3442.2***
(31.23)
1.rep78#0.~n -342.2
(-0.82)
1.rep78#1.~n 0
(.)
2.rep78#0.~n -88.47
(-0.38)
2.rep78#1.~n 0
(.)
3.rep78#0.~n 0
(.)
3.rep78#1.~n 0
(.)
4.rep78#0.~n 90.00
(0.41)
4.rep78#1.~n 197.8
(0.52)
5.rep78#0.~n -1482.2***
(-3.53)
5.rep78#1.~n 393.3
(1.03)
----------------------------
N 69
----------------------------
t statistics in parentheses
* p<0.05, ** p<0.01, *** p<0.001
.
. * Streamlined 2
. eststo clear
. regress ///
> weight ///
> ib0.foreign ///
> ib3.rep78#ib0.foreign
note: 1.rep78#1.foreign identifies no observations in the sample
note: 2.rep78#1.foreign identifies no observations in the sample
Source | SS df MS Number of obs = 69
-------------+---------------------------------- F(7, 61) = 9.90
Model | 22735950.7 7 3247992.95 Prob > F = 0.0000
Residual | 20009765.3 61 328028.939 R-squared = 0.5319
-------------+---------------------------------- Adj R-squared = 0.4782
Total | 42745715.9 68 628613.47 Root MSE = 572.74
-------------------------------------------------------------------------------
weight | Coef. Std. Err. t P>|t| [95% Conf. Interval]
--------------+----------------------------------------------------------------
foreign |
Foreign | -1432.222 348.5573 -4.11 0.000 -2129.206 -735.2388
|
rep78#foreign |
1#Domestic | -342.2222 419.7186 -0.82 0.418 -1181.501 497.057
1#Foreign | 0 (empty)
2#Domestic | -88.47222 230.549 -0.38 0.703 -549.4834 372.539
2#Foreign | 0 (empty)
4#Domestic | 90 220.447 0.41 0.685 -350.811 530.811
4#Foreign | 197.7778 381.8254 0.52 0.606 -565.7293 961.2849
5#Domestic | -1482.222 419.7186 -3.53 0.001 -2321.501 -642.943
5#Foreign | 393.3333 381.8254 1.03 0.307 -370.1738 1156.84
|
_cons | 3442.222 110.2235 31.23 0.000 3221.817 3662.628
-------------------------------------------------------------------------------
. esttab, mtitle title("Foreign or Domestic")
Foreign or Domestic
----------------------------
(1)
.
----------------------------
0.foreign 0
(.)
1.foreign -1432.2***
(-4.11)
1.rep78#0.~n -342.2
(-0.82)
1.rep78#1.~n 0
(.)
2.rep78#0.~n -88.47
(-0.38)
2.rep78#1.~n 0
(.)
3.rep78#0.~n 0
(.)
3.rep78#1.~n 0
(.)
4.rep78#0.~n 90.00
(0.41)
4.rep78#1.~n 197.8
(0.52)
5.rep78#0.~n -1482.2***
(-3.53)
5.rep78#1.~n 393.3
(1.03)
_cons 3442.2***
(31.23)
----------------------------
N 69
----------------------------
t statistics in parentheses
* p<0.05, ** p<0.01, *** p<0.001
.
. * using cts for binary
. eststo clear
. eststo, title(both): quietly regress ///
> weight ///
> c.foreign c.domestic ///
> ib3.rep78#c.foreign ///
> ib3.rep78#c.domestic ///
> , noc
(est1 stored)
. esttab, mtitle title("Foreign or Domestic")
Foreign or Domestic
----------------------------
(1)
both
----------------------------
foreign 2010.0***
(6.08)
domestic 3442.2***
(31.23)
1.rep78#c.~n 0
(.)
2.rep78#c.~n 0
(.)
3.rep78#c.~n 0
(.)
4.rep78#c.~n 197.8
(0.52)
5.rep78#c.~n 393.3
(1.03)
1.rep78#c.~c -342.2
(-0.82)
2.rep78#c.~c -88.47
(-0.38)
3.rep78#c.~c 0
(.)
4.rep78#c.~c 90.00
(0.41)
5.rep78#c.~c -1482.2***
(-3.53)
----------------------------
N 69
----------------------------
t statistics in parentheses
* p<0.05, ** p<0.01, *** p<0.001
.
. ///--- End Log and to HTML
> log close
name: <unnamed>
log: C:\Users\fan\Stata4Econ\reglin\discrete\fs_reg_d_interact.smcl
log type: smcl
closed on: 16 Aug 2019, 19:02:11
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------