------------------------------------------------------------------------------------------------------------------
      name:  <unnamed>
       log:  C:\Users\myend\Desktop\StataClass2.log
  log type:  text
 opened on:   6 Mar 2021, 11:47:08

. use "C:\Users\myend\Desktop\EE325Data.dta"

. * (1) Sorting data

. sort wei

. sort sex

. su cons

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
        cons |         66        7000    4397.552       1500      30000

. by sex: su cons

------------------------------------------------------------------------------------------------------------------
-> sex = Male

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
        cons |         30        7850    5366.162       2000      30000

------------------------------------------------------------------------------------------------------------------
-> sex = Female

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
        cons |         36    6291.667    3304.488       1500      13000


. by dec: su inc
not sorted
r(5);

. bysort dec: su inc

------------------------------------------------------------------------------------------------------------------
-> dec = 3

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
         inc |          4        7500    1914.854       6000      10000

------------------------------------------------------------------------------------------------------------------
-> dec = 4

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
         inc |          3        7500    2179.449       6000      10000

------------------------------------------------------------------------------------------------------------------
-> dec = 5

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
         inc |         19    11689.47    9793.983       4500      50000

------------------------------------------------------------------------------------------------------------------
-> dec = 6

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
         inc |         21     11861.9     5320.36       4000      25000

------------------------------------------------------------------------------------------------------------------
-> dec = 7

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
         inc |         18    11166.67    8438.358       3000      40000

------------------------------------------------------------------------------------------------------------------
-> dec = 8

    Variable |        Obs        Mean    Std. Dev.       Min        Max
-------------+---------------------------------------------------------
         inc |          1       10000           .      10000      10000


. * (2) Data manipulation

. gen incgr = 1 if inc<10000
(35 missing values generated)

. replace incgr = 2 if inc>=10000 & inc<40000
(33 real changes made)

. replace incgr = 3 if inc>=40000
(2 real changes made)

. tab inc incgr

           |              incgr
       inc |         1          2          3 |     Total
-----------+---------------------------------+----------
      3000 |         1          0          0 |         1 
      4000 |         2          0          0 |         2 
      4500 |         1          0          0 |         1 
      5000 |         1          0          0 |         1 
      5500 |         1          0          0 |         1 
      6000 |         7          0          0 |         7 
      6500 |         1          0          0 |         1 
      7000 |         3          0          0 |         3 
      7200 |         1          0          0 |         1 
      7300 |         1          0          0 |         1 
      8000 |         6          0          0 |         6 
      9000 |         5          0          0 |         5 
      9800 |         1          0          0 |         1 
     10000 |         0         15          0 |        15 
     10150 |         0          1          0 |         1 
     12000 |         0          4          0 |         4 
     13000 |         0          2          0 |         2 
     15000 |         0          4          0 |         4 
     18000 |         0          3          0 |         3 
     19000 |         0          1          0 |         1 
     19750 |         0          1          0 |         1 
     20000 |         0          1          0 |         1 
     25000 |         0          1          0 |         1 
     40000 |         0          0          1 |         1 
     50000 |         0          0          1 |         1 
-----------+---------------------------------+----------
     Total |        31         33          2 |        66 

. recode inc (0/10000=1) (10000/40000=2) (else=3), gen(incgr2)
(66 differences between inc and incgr2)

. tab incgr incgr2

           |          RECODE of inc
     incgr |         1          2          3 |     Total
-----------+---------------------------------+----------
         1 |        31          0          0 |        31 
         2 |        15         18          0 |        33 
         3 |         0          1          1 |         2 
-----------+---------------------------------+----------
     Total |        46         19          1 |        66 

. tab incgr2

  RECODE of |
        inc |      Freq.     Percent        Cum.
------------+-----------------------------------
          1 |         46       69.70       69.70
          2 |         19       28.79       98.48
          3 |          1        1.52      100.00
------------+-----------------------------------
      Total |         66      100.00

. recode inc (0/10000=1) (10001/39999=2) (else=3), gen(incgr3)
(66 differences between inc and incgr3)

. tab incgr incgr3

           |          RECODE of inc
     incgr |         1          2          3 |     Total
-----------+---------------------------------+----------
         1 |        31          0          0 |        31 
         2 |        15         18          0 |        33 
         3 |         0          0          2 |         2 
-----------+---------------------------------+----------
     Total |        46         18          2 |        66 

. tab incgr3

  RECODE of |
        inc |      Freq.     Percent        Cum.
------------+-----------------------------------
          1 |         46       69.70       69.70
          2 |         18       27.27       96.97
          3 |          2        3.03      100.00
------------+-----------------------------------
      Total |         66      100.00

. recode inc (0/9999=1) (10000/39999=2) (else=3), gen(incgr4)
(66 differences between inc and incgr4)

. tab incgr incgr4

           |          RECODE of inc
     incgr |         1          2          3 |     Total
-----------+---------------------------------+----------
         1 |        31          0          0 |        31 
         2 |         0         33          0 |        33 
         3 |         0          0          2 |         2 
-----------+---------------------------------+----------
     Total |        31         33          2 |        66 

. drop incgr2 incgr3 incgr4

. keep cons inc

. clear

. use "C:\Users\myend\Desktop\EE325Data.dta"

. * (3) Basic regression

. reg cons inc

      Source |       SS           df       MS      Number of obs   =        66
-------------+----------------------------------   F(1, 64)        =     80.34
       Model |   699644559         1   699644559   Prob > F        =    0.0000
    Residual |   557355441        64  8708678.77   R-squared       =    0.5566
-------------+----------------------------------   Adj R-squared   =    0.5497
       Total |  1.2570e+09        65  19338461.5   Root MSE        =      2951

------------------------------------------------------------------------------
        cons |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         inc |   .4387518   .0489504     8.96   0.000     .3409621    .5365415
       _cons |   2115.895   654.8842     3.23   0.002     807.6133    3424.177
------------------------------------------------------------------------------

. reg cons inc, l(99)

      Source |       SS           df       MS      Number of obs   =        66
-------------+----------------------------------   F(1, 64)        =     80.34
       Model |   699644559         1   699644559   Prob > F        =    0.0000
    Residual |   557355441        64  8708678.77   R-squared       =    0.5566
-------------+----------------------------------   Adj R-squared   =    0.5497
       Total |  1.2570e+09        65  19338461.5   Root MSE        =      2951

------------------------------------------------------------------------------
        cons |      Coef.   Std. Err.      t    P>|t|     [99% Conf. Interval]
-------------+----------------------------------------------------------------
         inc |   .4387518   .0489504     8.96   0.000     .3087956     .568708
       _cons |   2115.895   654.8842     3.23   0.002     377.2727    3854.517
------------------------------------------------------------------------------

. reg cons inc, l(50)

      Source |       SS           df       MS      Number of obs   =        66
-------------+----------------------------------   F(1, 64)        =     80.34
       Model |   699644559         1   699644559   Prob > F        =    0.0000
    Residual |   557355441        64  8708678.77   R-squared       =    0.5566
-------------+----------------------------------   Adj R-squared   =    0.5497
       Total |  1.2570e+09        65  19338461.5   Root MSE        =      2951

------------------------------------------------------------------------------
        cons |      Coef.   Std. Err.      t    P>|t|     [50% Conf. Interval]
-------------+----------------------------------------------------------------
         inc |   .4387518   .0489504     8.96   0.000     .4055466    .4719569
       _cons |   2115.895   654.8842     3.23   0.002     1671.659    2560.131
------------------------------------------------------------------------------

. bysort sex: reg cons inc

------------------------------------------------------------------------------------------------------------------
-> sex = Male

      Source |       SS           df       MS      Number of obs   =        30
-------------+----------------------------------   F(1, 28)        =     55.40
       Model |   554726352         1   554726352   Prob > F        =    0.0000
    Residual |   280348648        28  10012451.7   R-squared       =    0.6643
-------------+----------------------------------   Adj R-squared   =    0.6523
       Total |   835075000        29  28795689.7   Root MSE        =    3164.2

------------------------------------------------------------------------------
        cons |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         inc |   .4417649   .0593502     7.44   0.000     .3201915    .5633382
       _cons |   2391.259   933.5847     2.56   0.016     478.8972     4303.62
------------------------------------------------------------------------------

------------------------------------------------------------------------------------------------------------------
-> sex = Female

      Source |       SS           df       MS      Number of obs   =        36
-------------+----------------------------------   F(1, 34)        =     14.06
       Model |   111817772         1   111817772   Prob > F        =    0.0007
    Residual |   270369728        34  7952050.83   R-squared       =    0.2926
-------------+----------------------------------   Adj R-squared   =    0.2718
       Total |   382187500        35  10919642.9   Root MSE        =    2819.9

------------------------------------------------------------------------------
        cons |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
         inc |   .3969979   .1058699     3.75   0.001     .1818445    .6121514
       _cons |   2277.577   1169.093     1.95   0.060    -98.30694     4653.46
------------------------------------------------------------------------------

. log close
      name:  <unnamed>
       log:  C:\Users\myend\Desktop\StataClass2.log
  log type:  text
 closed on:   6 Mar 2021, 12:28:48
------------------------------------------------------------------------------------------------------------------
