import os
os.chdir('/Applications/Stata 17/utilities')
from pystata import config
config.init('mp')

Chapter 1: Review of linear regression

%%stata

net from http://www.stata-press.com/data/mlmus3/
. 
. net from http://www.stata-press.com/data/mlmus3/
-------------------------------------------------------------------------------
http://www.stata-press.com/data/mlmus3/
Files associated with text by Sophia Rabe-Hesketh and Anders Skrondal
-------------------------------------------------------------------------------

PACKAGES you could -net describe-:
    mlmus3_vol1       Files for Multilevel and Longitudinal Modeling Using
                        Stata, Third Edition, Volume 1
    mlmus3_vol2       Files for Multilevel and Longitudinal Modeling Using
                        Stata, Third Edition, Volume 2
-------------------------------------------------------------------------------

. 
%%stata

net describe mlmus3_vol1
. 
. net describe mlmus3_vol1

-------------------------------------------------------------------------------
package mlmus3_vol1 from http://www.stata-press.com/data/mlmus3
-------------------------------------------------------------------------------

TITLE
      do-files, data, datasets

DESCRIPTION/AUTHOR(S)
      Sophia Rabe-Hesketh, Anders Skrondal
      These are the files used to produce the examples in the book
      Multilevel and Longitudinal Modeling Using Stata, Third Edition

ANCILLARY FILES                             (type net get mlmus3_vol1)
      achievement.dta
      airlines.dta
      alcuse.dta
      anorexia.dta
      antisocial.dta
      army.dta
      asian.dta
      attend.dta
      birthwt.dta
      bp.dta
      calcium.dta
      ch1.do
      ch2.do
      ch3.do
      ch4.do
      ch5.do
      ch6.do
      ch7.do
      ch8.do
      ch9.do
      cigar.dta
      cogstyle.dta
      coursework.dta
      cropareas.dta
      dairy.dta
      data.cfk
      dialyzer.dta
      expectancy.dta
      ezunem.dta
      faculty.dta
      family.dta
      fat.dta
      fife.dta
      fringe.dta
      garrett.dta
      gcse.dta
      gpa.dta
      grader1.dta
      growth.dta
      grunfeld.dta
      headsize.dta
      homework.dta
      hours.dta
      hsb.dta
      instruction.dta
      kenya.dta
      neighborhood.dta
      nitrogen.dta
      ols.dta
      olympics.dta
      papke_did.dta
      part3intro.do
      pefr.dta
      postnatal.dta
      productivity.dta
      pups.dta
      reading.dta
      returns.dta
      schooleffects.dta
      sex.dta
      smoking.dta
      star1.dta
      star_mm.dta
      taxprep.dta
      twin.dta
      videos.dta
      wagepan.dta
      wheat.dta
-------------------------------------------------------------------------------

. 
%%stata

net get mlmus3_vol1
. 
. net get mlmus3_vol1
checking mlmus3_vol1 consistency and verifying not already installed...

copying into current directory...
      copying  achievement.dta
      copying  airlines.dta
      copying  alcuse.dta
      copying  anorexia.dta
      copying  antisocial.dta
      copying  army.dta
      copying  asian.dta
      copying  attend.dta
      copying  birthwt.dta
      copying  bp.dta
      copying  calcium.dta
      copying  ch1.do
      copying  ch2.do
      copying  ch3.do
      copying  ch4.do
      copying  ch5.do
      copying  ch6.do
      copying  ch7.do
      copying  ch8.do
      copying  ch9.do
      copying  cigar.dta
      copying  cogstyle.dta
      copying  coursework.dta
      copying  cropareas.dta
      copying  dairy.dta
      copying  data.cfk
      copying  dialyzer.dta
      copying  expectancy.dta
      copying  ezunem.dta
      copying  faculty.dta
      copying  family.dta
      copying  fat.dta
      copying  fife.dta
      copying  fringe.dta
      copying  garrett.dta
      copying  gcse.dta
      copying  gpa.dta
      copying  grader1.dta
      copying  growth.dta
      copying  grunfeld.dta
      copying  headsize.dta
      copying  homework.dta
      copying  hours.dta
      copying  hsb.dta
      copying  instruction.dta
      copying  kenya.dta
      copying  neighborhood.dta
      copying  nitrogen.dta
      copying  ols.dta
      copying  olympics.dta
      copying  papke_did.dta
      copying  part3intro.do
      copying  pefr.dta
      copying  postnatal.dta
      copying  productivity.dta
      copying  pups.dta
      copying  reading.dta
      copying  returns.dta
      copying  schooleffects.dta
      copying  sex.dta
      copying  smoking.dta
      copying  star1.dta
      copying  star_mm.dta
      copying  taxprep.dta
      copying  twin.dta
      copying  videos.dta
      copying  wagepan.dta
      copying  wheat.dta
ancillary files successfully copied.

. 
%%stata

use pefr
. 
. use pefr

. 
%%stata
describe
Contains data from pefr.dta
 Observations:            17                  
    Variables:             5                  26 Nov 2004 15:45
-------------------------------------------------------------------------------
Variable      Storage   Display    Value
    name         type    format    label      Variable label
-------------------------------------------------------------------------------
id              float   %9.0g                 
wp1             float   %9.0g                 
wp2             float   %9.0g                 
wm1             float   %9.0g                 
wm2             float   %9.0g                 
-------------------------------------------------------------------------------
Sorted by: 
%%stata

use http://www.stata-press.com/data/mlmus3/faculty
use http://www.stata-press.com/data/mlmus3/faculty, clear
. 
. use http://www.stata-press.com/data/mlmus3/faculty

. use http://www.stata-press.com/data/mlmus3/faculty, clear

. 
%%stata

tabstat salary, by(male) statistics(mean sd n)
. 
. tabstat salary, by(male) statistics(mean sd n)

Summary for variables: salary
Group variable: male 

  male |      Mean        SD         N
-------+------------------------------
 Women |   42916.6   9161.61       128
   Men |  53499.24  12583.48       386
-------+------------------------------
 Total |  50863.87  12672.77       514
--------------------------------------

. 
%%stata

graph box salary, over(male) ytitle(Academic salary) asyvars
. 
. graph box salary, over(male) ytitle(Academic salary) asyvars

. 
svg
svg
%%stata

generate lsalary = log10(salary)
graph box lsalary, over(male) ytitle(Log academic salary) asyvars
histogram lsalary, by(male, rows(2)) xtitle(Log academic salary)
. 
. generate lsalary = log10(salary)

. graph box lsalary, over(male) ytitle(Log academic salary) asyvars

. histogram lsalary, by(male, rows(2)) xtitle(Log academic salary)

. 
svg
svg
%%stata

ttest salary, by(male)
ttest salary, by(male) unequal
anova salary male
margins male
. 
. ttest salary, by(male)

Two-sample t test with equal variances
------------------------------------------------------------------------------
   Group |     Obs        Mean    Std. err.   Std. dev.   [95% conf. interval]
---------+--------------------------------------------------------------------
   Women |     128     42916.6    809.7795     9161.61     41314.2    44519.01
     Men |     386    53499.24    640.4822    12583.48    52239.96    54758.52
---------+--------------------------------------------------------------------
Combined |     514    50863.87     558.972    12672.77    49765.72    51962.03
---------+--------------------------------------------------------------------
    diff |           -10582.63    1206.345               -12952.63   -8212.636
------------------------------------------------------------------------------
    diff = mean(Women) - mean(Men)                                t =  -8.7725
H0: diff = 0                                     Degrees of freedom =      512

    Ha: diff < 0                 Ha: diff != 0                 Ha: diff > 0
 Pr(T < t) = 0.0000         Pr(|T| > |t|) = 0.0000          Pr(T > t) = 1.0000

. ttest salary, by(male) unequal

Two-sample t test with unequal variances
------------------------------------------------------------------------------
   Group |     Obs        Mean    Std. err.   Std. dev.   [95% conf. interval]
---------+--------------------------------------------------------------------
   Women |     128     42916.6    809.7795     9161.61     41314.2    44519.01
     Men |     386    53499.24    640.4822    12583.48    52239.96    54758.52
---------+--------------------------------------------------------------------
Combined |     514    50863.87     558.972    12672.77    49765.72    51962.03
---------+--------------------------------------------------------------------
    diff |           -10582.63    1032.454               -12614.48   -8550.787
------------------------------------------------------------------------------
    diff = mean(Women) - mean(Men)                                t = -10.2500
H0: diff = 0                     Satterthwaite's degrees of freedom =  297.227

    Ha: diff < 0                 Ha: diff != 0                 Ha: diff > 0
 Pr(T < t) = 0.0000         Pr(|T| > |t|) = 0.0000          Pr(T > t) = 1.0000

. anova salary male

                         Number of obs =        514    R-squared     =  0.1307
                         Root MSE      =    11827.4    Adj R-squared =  0.1290

                  Source | Partial SS         df         MS        F    Prob>F
              -----------+----------------------------------------------------
                   Model |  1.077e+10          1   1.077e+10     76.96  0.0000
                         |
                    male |  1.077e+10          1   1.077e+10     76.96  0.0000
                         |
                Residual |  7.162e+10        512   1.399e+08  
              -----------+----------------------------------------------------
                   Total |  8.239e+10        513   1.606e+08  

. margins male

Adjusted predictions                                       Number of obs = 514

Expression: Linear prediction, predict()

------------------------------------------------------------------------------
             |            Delta-method
             |     Margin   std. err.      t    P>|t|     [95% conf. interval]
-------------+----------------------------------------------------------------
        male |
      Women  |    42916.6   1045.403    41.05   0.000      40862.8    44970.41
        Men  |   53499.24   601.9981    88.87   0.000     52316.55    54681.93
------------------------------------------------------------------------------

. 
%%stata

reg salary market
reg lsalary market
. 
. reg salary market

      Source |       SS           df       MS      Number of obs   =       514
-------------+----------------------------------   F(1, 512)       =    101.77
       Model |  1.3661e+10         1  1.3661e+10   Prob > F        =    0.0000
    Residual |  6.8726e+10       512   134231433   R-squared       =    0.1658
-------------+----------------------------------   Adj R-squared   =    0.1642
       Total |  8.2387e+10       513   160599133   Root MSE        =     11586

------------------------------------------------------------------------------
      salary | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
-------------+----------------------------------------------------------------
      market |   34545.22   3424.333    10.09   0.000     27817.75    41272.69
       _cons |   18096.99   3288.009     5.50   0.000     11637.35    24556.64
------------------------------------------------------------------------------

. reg lsalary market

      Source |       SS           df       MS      Number of obs   =       514
-------------+----------------------------------   F(1, 512)       =    107.58
       Model |  1.04818106         1  1.04818106   Prob > F        =    0.0000
    Residual |  4.98852929       512  .009743221   R-squared       =    0.1736
-------------+----------------------------------   Adj R-squared   =    0.1720
       Total |  6.03671035       513  .011767467   Root MSE        =    .09871

------------------------------------------------------------------------------
     lsalary | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
-------------+----------------------------------------------------------------
      market |   .3025987   .0291743    10.37   0.000     .2452827    .3599147
       _cons |   4.405958   .0280128   157.28   0.000     4.350924    4.460992
------------------------------------------------------------------------------

. 
%%stata
egen mn_market = mean(market)
generate marketc = market - mn_market
%%stata


regress salary market

regress salary marketc
. 
. 
. regress salary market

      Source |       SS           df       MS      Number of obs   =       514
-------------+----------------------------------   F(1, 512)       =    101.77
       Model |  1.3661e+10         1  1.3661e+10   Prob > F        =    0.0000
    Residual |  6.8726e+10       512   134231433   R-squared       =    0.1658
-------------+----------------------------------   Adj R-squared   =    0.1642
       Total |  8.2387e+10       513   160599133   Root MSE        =     11586

------------------------------------------------------------------------------
      salary | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
-------------+----------------------------------------------------------------
      market |   34545.22   3424.333    10.09   0.000     27817.75    41272.69
       _cons |   18096.99   3288.009     5.50   0.000     11637.35    24556.64
------------------------------------------------------------------------------

. 
. regress salary marketc

      Source |       SS           df       MS      Number of obs   =       514
-------------+----------------------------------   F(1, 512)       =    101.77
       Model |  1.3661e+10         1  1.3661e+10   Prob > F        =    0.0000
    Residual |  6.8726e+10       512   134231433   R-squared       =    0.1658
-------------+----------------------------------   Adj R-squared   =    0.1642
       Total |  8.2387e+10       513   160599133   Root MSE        =     11586

------------------------------------------------------------------------------
      salary | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
-------------+----------------------------------------------------------------
     marketc |   34545.22   3424.333    10.09   0.000     27817.75    41272.69
       _cons |   50863.87    511.029    99.53   0.000      49859.9    51867.85
------------------------------------------------------------------------------

. 

Konstantanya saja yang berubah

%%stata
predict yhat, xb
%%stata
twoway (scatter salary market) (line yhat market), ytitle(Academic salary) xtitle(Marketability)
svg
svg
%%stata
regress salary male
regress salary male, vce(robust)
regress salary male, robust
. regress salary male

      Source |       SS           df       MS      Number of obs   =       514
-------------+----------------------------------   F(1, 512)       =     76.96
       Model |  1.0765e+10         1  1.0765e+10   Prob > F        =    0.0000
    Residual |  7.1622e+10       512   139887048   R-squared       =    0.1307
-------------+----------------------------------   Adj R-squared   =    0.1290
       Total |  8.2387e+10       513   160599133   Root MSE        =     11827

------------------------------------------------------------------------------
      salary | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
-------------+----------------------------------------------------------------
        male |   10582.63   1206.345     8.77   0.000     8212.636    12952.63
       _cons |    42916.6   1045.403    41.05   0.000      40862.8    44970.41
------------------------------------------------------------------------------

. regress salary male, vce(robust)

Linear regression                               Number of obs     =        514
                                                F(1, 512)         =     105.26
                                                Prob > F          =     0.0000
                                                R-squared         =     0.1307
                                                Root MSE          =      11827

------------------------------------------------------------------------------
             |               Robust
      salary | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
-------------+----------------------------------------------------------------
        male |   10582.63   1031.462    10.26   0.000     8556.213    12609.05
       _cons |    42916.6    808.184    53.10   0.000     41328.84    44504.37
------------------------------------------------------------------------------

. regress salary male, robust

Linear regression                               Number of obs     =        514
                                                F(1, 512)         =     105.26
                                                Prob > F          =     0.0000
                                                R-squared         =     0.1307
                                                Root MSE          =      11827

------------------------------------------------------------------------------
             |               Robust
      salary | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
-------------+----------------------------------------------------------------
        male |   10582.63   1031.462    10.26   0.000     8556.213    12609.05
       _cons |    42916.6    808.184    53.10   0.000     41328.84    44504.37
------------------------------------------------------------------------------

. 

1.7 Multiple linear regression

%%stata
tabstat marketc, by(male) statistics(mean sd)
Summary for variables: marketc
Group variable: male 

  male |      Mean        SD
-------+--------------------
 Women | -.0469589  .1314393
   Men |  .0155718  .1518486
-------+--------------------
 Total | -2.96e-08    .14938
----------------------------
%%stata
regress salary male marketc
predict yhat2, xb
. regress salary male marketc

      Source |       SS           df       MS      Number of obs   =       514
-------------+----------------------------------   F(2, 511)       =     85.80
       Model |  2.0711e+10         2  1.0356e+10   Prob > F        =    0.0000
    Residual |  6.1676e+10       511   120696838   R-squared       =    0.2514
-------------+----------------------------------   Adj R-squared   =    0.2485
       Total |  8.2387e+10       513   160599133   Root MSE        =     10986

------------------------------------------------------------------------------
      salary | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
-------------+----------------------------------------------------------------
        male |   8708.423   1139.411     7.64   0.000     6469.917    10946.93
     marketc |    29972.6   3301.766     9.08   0.000     23485.89     36459.3
       _cons |   44324.09   983.3533    45.07   0.000     42392.17       46256
------------------------------------------------------------------------------

. predict yhat2, xb

. 
%%stata

twoway (scatter salary marketc if male==1, msymbol(o)) (line yhat2 marketc if male==1, sort lpatt(dash)) (scatter salary marketc if male==0, msymbol(oh)) 
(line yhat2 marketc if male==0, sort lpatt(solid)),
ytitle(Academic salary)
xtitle(Mean-centered marketability)
legend(order(1 " " 2 "Men" 3 " " 4 "Women"))
. 
. twoway (scatter salary marketc if male==1, msymbol(o)) (line yhat2 marketc if
>  male==1, sort lpatt(dash)) (scatter salary marketc if male==0, msymbol(oh)) 


Exception in thread Stata:
Traceback (most recent call last):
  File "/opt/anaconda3/lib/python3.11/threading.py", line 1045, in _bootstrap_inner
    self.run()
  File "/Applications/Stata 17/utilities/pystata/core/stout.py", line 176, in run
    raise SystemError(output)
SystemError: 
. (line yhat2 marketc if male==0, sort lpatt(solid)),
( is not a valid command name
r(199);
r(199);
svg
svg
%%stata

regress salary male marketc yearsdg
ovtest

scatter salary marketc
. 
. regress salary male marketc yearsdg

      Source |       SS           df       MS      Number of obs   =       514
-------------+----------------------------------   F(3, 510)       =    367.56
       Model |  5.6333e+10         3  1.8778e+10   Prob > F        =    0.0000
    Residual |  2.6054e+10       510  51087083.4   R-squared       =    0.6838
-------------+----------------------------------   Adj R-squared   =    0.6819
       Total |  8.2387e+10       513   160599133   Root MSE        =    7147.5

------------------------------------------------------------------------------
      salary | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
-------------+----------------------------------------------------------------
        male |   2040.211    783.122     2.61   0.009     501.6684    3578.753
     marketc |   38402.39   2171.689    17.68   0.000     34135.83    42668.95
     yearsdg |   949.2583   35.94867    26.41   0.000     878.6326    1019.884
       _cons |    34834.3   733.7898    47.47   0.000     33392.68    36275.93
------------------------------------------------------------------------------

. ovtest

Ramsey RESET test for omitted variables
Omitted: Powers of fitted values of salary

H0: Model has no omitted variables

F(3, 507) =   1.50
 Prob > F = 0.2135

. 
. scatter salary marketc

. 
svg
svg
%%stata

regress salary i.male marketc yearsdg
margins male, at(marketc=0 yearsdg=10)
margins male, at(marketc=0 yearsdg=0)

display 2040.211+34834.3
. 
. regress salary i.male marketc yearsdg

      Source |       SS           df       MS      Number of obs   =       514
-------------+----------------------------------   F(3, 510)       =    367.56
       Model |  5.6333e+10         3  1.8778e+10   Prob > F        =    0.0000
    Residual |  2.6054e+10       510  51087083.4   R-squared       =    0.6838
-------------+----------------------------------   Adj R-squared   =    0.6819
       Total |  8.2387e+10       513   160599133   Root MSE        =    7147.5

------------------------------------------------------------------------------
      salary | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
-------------+----------------------------------------------------------------
        male |
        Men  |   2040.211    783.122     2.61   0.009     501.6684    3578.753
     marketc |   38402.39   2171.689    17.68   0.000     34135.83    42668.95
     yearsdg |   949.2583   35.94867    26.41   0.000     878.6326    1019.884
       _cons |    34834.3   733.7898    47.47   0.000     33392.68    36275.93
------------------------------------------------------------------------------

. margins male, at(marketc=0 yearsdg=10)

Adjusted predictions                                       Number of obs = 514
Model VCE: OLS

Expression: Linear prediction, predict()
At: marketc =  0
    yearsdg = 10

------------------------------------------------------------------------------
             |            Delta-method
             |     Margin   std. err.      t    P>|t|     [95% conf. interval]
-------------+----------------------------------------------------------------
        male |
      Women  |   44326.89   639.7602    69.29   0.000        43070    45583.78
        Men  |    46367.1   444.0554   104.42   0.000      45494.7     47239.5
------------------------------------------------------------------------------

. margins male, at(marketc=0 yearsdg=0)

Adjusted predictions                                       Number of obs = 514
Model VCE: OLS

Expression: Linear prediction, predict()
At: marketc = 0
    yearsdg = 0

------------------------------------------------------------------------------
             |            Delta-method
             |     Margin   std. err.      t    P>|t|     [95% conf. interval]
-------------+----------------------------------------------------------------
        male |
      Women  |    34834.3   733.7898    47.47   0.000     33392.68    36275.93
        Men  |   36874.52   712.6708    51.74   0.000     35474.38    38274.65
------------------------------------------------------------------------------

. 
. display 2040.211+34834.3
36874.511

. 
%%stata

generate male_years = male*yearsdg
. 
. generate male_years = male*yearsdg

. 
%%stata
regress salary male marketc yearsdg male_years, robust
Linear regression                               Number of obs     =        514
                                                F(4, 509)         =     271.67
                                                Prob > F          =     0.0000
                                                R-squared         =     0.6875
                                                Root MSE          =     7112.1

------------------------------------------------------------------------------
             |               Robust
      salary | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
-------------+----------------------------------------------------------------
        male |  -593.3088   1014.158    -0.59   0.559    -2585.759    1399.142
     marketc |   38436.65   2237.322    17.18   0.000     34041.12    42832.17
     yearsdg |   763.1896    64.1736    11.89   0.000     637.1118    889.2673
  male_years |   227.1532   77.61123     2.93   0.004     74.67539     379.631
       _cons |   36773.64   735.2791    50.01   0.000     35329.09     38218.2
------------------------------------------------------------------------------
%%stata
lincom male + male_years*10
 ( 1)  male + 10*male_years = 0

------------------------------------------------------------------------------
      salary | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
-------------+----------------------------------------------------------------
         (1) |   1678.223   643.1395     2.61   0.009     414.6882    2941.758
------------------------------------------------------------------------------
%%stata
twoway (function Women = 36773 + 763.19*x, range(0 41) lpatt(dash)) ///
       (function Men = 36773 + -593.31 + (763.19 + 227.15)*x, range(0 41) lpatt(solid)), ///
       xtitle("Time since degree (years)") ytitle("Mean salary")
. twoway (function Women = 36773 + 763.19*x, range(0 41) lpatt(dash)) ///
>        (function Men = 36773 + -593.31 + (763.19 + 227.15)*x, range(0 41) lpa
> tt(solid)), ///
>        xtitle("Time since degree (years)") ytitle("Mean salary")

. 
svg
svg
%%stata

twoway (function Women = _b[_cons] + _b[yearsdg]*x, range(0 41) lpatt(dash)) ///
       (function Men = _b[_cons] + _b[male] + (_b[yearsdg] + _b[male_years])*x, ///
       range(0 41) lpatt(solid)), xtitle("Time since degree (years)") ytitle("Mean salary")
. 
. twoway (function Women = _b[_cons] + _b[yearsdg]*x, range(0 41) lpatt(dash)) 
> ///
>        (function Men = _b[_cons] + _b[male] + (_b[yearsdg] + _b[male_years])*
> x, ///
>        range(0 41) lpatt(solid)), xtitle("Time since degree (years)") ytitle(
> "Mean salary")

. 
svg
svg
%%stata

regress salary male marketc yearsdg i.male#c.yearsdg
. 
. regress salary male marketc yearsdg i.male#c.yearsdg

      Source |       SS           df       MS      Number of obs   =       514
-------------+----------------------------------   F(4, 509)       =    279.95
       Model |  5.6641e+10         4  1.4160e+10   Prob > F        =    0.0000
    Residual |  2.5746e+10       509  50581607.4   R-squared       =    0.6875
-------------+----------------------------------   Adj R-squared   =    0.6850
       Total |  8.2387e+10       513   160599133   Root MSE        =    7112.1

------------------------------------------------------------------------------
      salary | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
-------------+----------------------------------------------------------------
        male |  -593.3088   1320.911    -0.45   0.654    -3188.418      2001.8
     marketc |   38436.65   2160.963    17.79   0.000     34191.14    42682.15
     yearsdg |   763.1896    83.4169     9.15   0.000     599.3057    927.0734
             |
        male#|
   c.yearsdg |
        Men  |   227.1532   91.99749     2.47   0.014     46.41164    407.8947
             |
       _cons |   36773.64   1072.395    34.29   0.000     34666.78    38880.51
------------------------------------------------------------------------------

. 
%%stata

regress salary male marketc yearsdg i.male##c.yearsdg
lincom 1.male + 1.male#c.yearsdg*10
. 
. regress salary male marketc yearsdg i.male##c.yearsdg
note: 1.male omitted because of collinearity.
note: yearsdg omitted because of collinearity.

      Source |       SS           df       MS      Number of obs   =       514
-------------+----------------------------------   F(4, 509)       =    279.95
       Model |  5.6641e+10         4  1.4160e+10   Prob > F        =    0.0000
    Residual |  2.5746e+10       509  50581607.4   R-squared       =    0.6875
-------------+----------------------------------   Adj R-squared   =    0.6850
       Total |  8.2387e+10       513   160599133   Root MSE        =    7112.1

------------------------------------------------------------------------------
      salary | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
-------------+----------------------------------------------------------------
        male |  -593.3088   1320.911    -0.45   0.654    -3188.418      2001.8
     marketc |   38436.65   2160.963    17.79   0.000     34191.14    42682.15
     yearsdg |   763.1896    83.4169     9.15   0.000     599.3057    927.0734
             |
        male |
        Men  |          0  (omitted)
     yearsdg |          0  (omitted)
             |
        male#|
   c.yearsdg |
        Men  |   227.1532   91.99749     2.47   0.014     46.41164    407.8947
             |
       _cons |   36773.64   1072.395    34.29   0.000     34666.78    38880.51
------------------------------------------------------------------------------

. lincom 1.male + 1.male#c.yearsdg*10

 ( 1)  1o.male + 10*1.male#c.yearsdg = 0

------------------------------------------------------------------------------
      salary | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
-------------+----------------------------------------------------------------
         (1) |   2271.532   919.9749     2.47   0.014     464.1164    4078.947
------------------------------------------------------------------------------

.