CH 1 Courier New 9, 1 spac
. summarize
Variable | Obs Mean Std. Dev. Min Max ---+--- wage | 1,000 20.20122 12.1038 2.03 72.13
educ | 1,000 10.689 2.44013 1 16
exper | 1,000 26.501 12.99041 3 64
hrswk | 1,000 39.24 11.44611 0 99
married | 1,000 .608 .488441 0 1
---+--- female | 1,000 .492 .5001862 0 1
metro | 1,000 .805 .396399 0 1
Asiant | 1,000 .256 .4366402 0 1
south | 1,000 .31 .4627247 0 1
west | 1,000 .245 .4303024 0 1
---+--- black | 1,000 .096 .2947386 0 1
Asian | 1,000 .049 .215976 0 1
. describe
Contains data from /Users/purwantowidodo/Desktop/Using Stata/Data Principle Econo/Lat-1.dta
obs: 1,000
vars: 12 2 May 2020 10:40 size: 19,000
--- ---
storage display value
variable name type format label variable label
--- ---
wage double %10.0g wage educ byte %10.0g educ exper byte %10.0g exper hrswk byte %10.0g hrswk married byte %10.0g married female byte %10.0g female metro byte %10.0g metro midwest byte %10.0g midwest south byte %10.0g south west byte %10.0g west black byte %10.0g black asian byte %10.0g asian
. list wage in 1/5 menampilkan variable wage mulai no 1 sampai dengan 5 +---+
| wage | |---|
1. | 16.5 | 2. | 14.4 | 3. | 15 | 4. | 12.7 | 5. | 10.8 | +---+
list wage in 5/10 variable wage mulai dari 5 sampai dengan 10 +---+
| wage |
|---|
5. | 10.8 | 6. | 28.38 | 7. | 16.25 | 8. | 27.7 | 9. | 10 | |---|
10. | 27 | +---+
. summarize wage if female == 1 summary wage stat khusus female Variable | Obs Mean Std. Dev. Min Max ---+--- wage | 492 17.62433 10.28887 2.5 72.13
. summarize wage, detail
wage
--- Percentiles Smallest
1% 3.895 2.03 5% 7.2 2.5
10% 8.275 2.83 Obs 1,000 25% 12 2.88 Sum of Wgt. 1,000 50% 16.5 Mean 20.20122 Largest Std. Dev. 12.1038 75% 25.4 72.13
90% 36.96 72.13 Variance 146.5021 95% 45.175 72.13 Skewness 1.478395 99% 62.58 72.13 Kurtosis 5.475637 . summarize wage if female == 1, detail
wage
--- Percentiles Smallest
1% 3.85 2.5 5% 7 2.89
10% 7.7 3.33 Obs 492 25% 10.25 3.75 Sum of Wgt. 492 50% 15 Mean 17.62433 Largest Std. Dev. 10.28887 75% 21.985 61.05
90% 30 65.71 Variance 105.8609 95% 38.46 71.22 Skewness 1.764697 99% 60.1 72.13 Kurtosis 7.593897 . summarize wage if female == 1 in 1/100, detail
wage
--- Percentiles Smallest
1% 3.75 3.75 5% 6 5.49
10% 7 6 Obs 46 25% 12 6.73 Sum of Wgt. 46 50% 15.835 Mean 20.00413 Largest Std. Dev. 15.38761 75% 21 42.5
90% 36.35 65.71 Variance 236.7787 95% 65.71 71.22 Skewness 2.246746 99% 72.13 72.13 Kurtosis 7.812908
. . tabulate utown utown variable dummy
utown | Freq. Percent Cum.
---+--- 0 | 481 48.10 48.10 1 | 519 51.90 100.00 ---+--- Total | 1,000 100.00
. tabulate utown, summarize (price)
| Summary of price
utown | Mean Std. Dev. Freq.
---+--- 0 | 215.73249 26.737362 481 1 | 277.2416 30.78208 519 ---+--- Total | 247.65572 42.192729 1,000
. tabulate utown pool | pool
utown | 0 1 | Total ---+---+--- 0 | 387 94 | 481 1 | 409 110 | 519 ---+---+--- Total | 796 204 | 1,000
. tabulate utown pool, chi2 | pool
utown | 0 1 | Total ---+---+--- 0 | 387 94 | 481 1 | 409 110 | 519 ---+---+--- Total | 796 204 | 1,000 Pearson chi2(1) = 0.4195 Pr = 0.517 .
. tabulate utown pool, chi2 row col +---+
| Key |
|---|
| frequency |
| row percentage |
| column percentage | +---+
| pool
utown | 0 1 | Total ---+---+--- 0 | 387 94 | 481 | 80.46 19.54 | 100.00 | 48.62 46.08 | 48.10 ---+---+--- 1 | 409 110 | 519 | 78.81 21.19 | 100.00 | 51.38 53.92 | 51.90 ---+---+--- Total | 796 204 | 1,000 | 79.60 20.40 | 100.00 | 100.00 100.00 | 100.00 Pearson chi2(1) = 0.4195 Pr = 0.517 . tabulate utown pool, cell chi2 row col
+---+
| Key |
|---|
| frequency |
| row percentage |
| column percentage |
| cell percentage | +---+
| pool
utown | 0 1 | Total ---+---+--- 0 | 387 94 | 481 | 80.46 19.54 | 100.00 | 48.62 46.08 | 48.10 | 38.70 9.40 | 48.10 ---+---+--- 1 | 409 110 | 519 | 78.81 21.19 | 100.00 | 51.38 53.92 | 51.90 | 40.90 11.00 | 51.90 ---+---+--- Total | 796 204 | 1,000 | 79.60 20.40 | 100.00 | 100.00 100.00 | 100.00 | 79.60 20.40 | 100.00 Pearson chi2(1) = 0.4195 Pr = 0.517 . tabulate utown pool, cell chi2 col
+---+
| Key |
|---|
| frequency |
| column percentage |
| cell percentage | +---+
| pool
utown | 0 1 | Total ---+---+--- 0 | 387 94 | 481 | 48.62 46.08 | 48.10 | 38.70 9.40 | 48.10 ---+---+--- 1 | 409 110 | 519 | 51.38 53.92 | 51.90 | 40.90 11.00 | 51.90 ---+---+--- Total | 796 204 | 1,000 | 100.00 100.00 | 100.00 | 79.60 20.40 | 100.00 Pearson chi2(1) = 0.4195 Pr = 0.517 .
histogram wage, percent title(histogram of wage data) (bin=29, start=2.03, width=2.4172414)
. twoway (scatter educ wage), ytitle(educ) xtitle(wage) title(Latihan)
twoway (scatter wage educ), ytitle(wage) xtitle(educ) title(Latihan)
twoway (scatter wage educ), ytitle(Gaji) xtitle(Pendidikan) title(Latihan)
.
Stata treats categorical variables as factor variables. They are designated in operations with an “i.” prefix, such as i.female or i.black. To designate a variable as continuous use the prefix “c.”, as in c.wage. Variables such as years of education or experience can be treated as either. This designation can be used in statistical analyses by using these prefixes. See help factor variables. For example,
. summarize female
Variable | Obs Mean Std. Dev. Min Max ---+--- female | 1,000 .492 .5001862 0 1 . summarize i.female yang ditampilkan hanya dummy variable = 1 Variable | Obs Mean Std. Dev. Min Max ---+--- 1.female | 1,000 .492 .5001862 0 1
summarize ibn.female per-kategori
Variable | Obs Mean Std. Dev. Min Max ---+--- female |
0 | 1,000 .508 .5001862 0 1 1 | 1,000 .492 .5001862 0 1
. summarize i.female#c.wage
Variable | Obs Mean Std. Dev. Min Max ---+--- female#|
c.wage |
0 | 1,000 11.53005 14.72815 0 72.13 1 | 1,000 8.67117 11.39043 0 72.13
. summarize i.female#i.married
Variable | Obs Mean Std. Dev. Min Max ---+--- female#|
married |
0 1 | 1,000 .317 .4655403 0 1 1 0 | 1,000 .201 .4009486 0 1 1 1 | 1,000 .291 .4544508 0 1 . summarize i.female##(c.wage i.married)
Variable | Obs Mean Std. Dev. Min Max ---+--- 1.female | 1,000 .492 .5001862 0 1 wage | 1,000 20.20122 12.1038 2.03 72.13 1.married | 1,000 .608 .488441 0 1 |
female#|
c.wage |
1 | 1,000 8.67117 11.39043 0 72.13 ---+--- |
female#|
married |
1 1 | 1,000 .291 .4544508 0 1 . summarize
Variable | Obs Mean Std. Dev. Min Max ---+--- food_exp | 40 283.5735 112.6752 109.71 587.66 income | 40 19.60475 6.847773 3.69 33.4
. describe
Contains data from /Users/purwantowidodo/Desktop/Using Stata/Data Principle Econo/food.dta
obs: 40
vars: 2 11 Dec 2019 10:52 size: 640
--- ---
storage display value
variable name type format label variable label
--- ---
food_exp double %10.0g food_exp income double %10.0g income
--- ---
Sorted by:
. summarize food_exp if income <=10
Variable | Obs Mean Std. Dev. Min Max ---+--- food_exp | 4 121.375 9.941219 114.96 135.98
. twoway (scatter food_exp income)
twoway (scatter food_exp income), ytitle(makanan) ylabel(0(100)600) xtitle(pendapatan) xlabel(0(5)35) title(Latihan)
ylabel(nilai awal(selang)nilai akhir)
Analisis regresi
. regress food_exp income
Source | SS df MS Number of obs = 40 ---+--- F(1, 38) = 23.79 Model | 190626.984 1 190626.984 Prob > F = 0.0000 Residual | 304505.176 38 8013.2941 R-squared = 0.3850 ---+--- Adj R-squared = 0.3688 Total | 495132.16 39 12695.6964 Root MSE = 89.517 --- food_exp | Coef. Std. Err. t P>|t| [95% Conf. Interval]
---+--- income | 10.20964 2.093264 4.88 0.000 5.972052 14.44723 _cons | 83.416 43.41016 1.92 0.062 -4.463279 171.2953 --- . margins, eyex(income)
Average marginal effects Number of obs = 40 Model VCE : OLS
Expression : Linear prediction, predict() ey/ex w.r.t. : income
--- | Delta-method
| ey/ex Std. Err. t P>|t| [95% Conf. Interval]
---+--- income | .6796126 .1466535 4.63 0.000 .382728 .9764971 --- . margins, eyex(income) atmeans
Conditional marginal effects Number of obs = 40 Model VCE : OLS
Expression : Linear prediction, predict() ey/ex w.r.t. : income
at : income = 19.60475 (mean)
--- | Delta-method
| ey/ex Std. Err. t P>|t| [95% Conf. Interval]
---+--- income | .7058399 .1489436 4.74 0.000 .4043194 1.00736 --- . summarize
Variable | Obs Mean Std. Dev. Min Max ---+--- food_exp | 40 283.5735 112.6752 109.71 587.66 income | 40 19.60475 6.847773 3.69 33.4 elastisitas:
6 6 C h a p t e r 2
T h e o p t i o n
r e s i d u a l sc a n b e s h o r t e n e d t o t h e m i n i m u m o f
r, o r a b i t l o n g e r l i k e
r e so r
r e s i d.
2 .4 .2 C o m p u tin g a n e la s tic i ty
G i v e n t h e p a r a m e t e r e s t i m a t e s , a n d t h e s u m m a r y s t a t i s t i c s f o r t h e v a r i a b l e s , w e c a n e a s i l y c o m p u t e o t h e r q u a n t i t i e s , l i k e t h e e l a s t i c i t y o f f o o d e x p e n d i t u r e w i t h r e s p e c t t o i n c o m e , e v a l u a t e d a t t h e m e a n s
2
1 9 . 6 0
ˆ 1 0 . 2 1 0 . 7 1
2 8 3 . 5 7 b x
H ˜ y u
O n e o f S t a t a ’ s p o s t - e s t i m a t i o n c o m m a n d s a l l o w s c o m p u t i n g t h i s e l a s t i c i t y a u t o m a t i c a l l y . S e l e c t S t a t i s t i c s > P o s t e s t i m a t i o n > M a r g i n a l e ffe c t s .
I n t h e r e s u l t i n g d i a l o g b o x s e l e c t t h e r a d i o b u t t o n f o r E l a s t i c i t i e s a n d t h e V a r i a b l e . I n o u r s i m p l e r e g r e s s i o n m o d e l t h e r e i s o n l y o n e v a r i a b l e t o s e l e c t , i n c o m e . T o e v a l u a t e t h e e l a s t i c i t y a t t h e s a m p l e m e a n s s e l e c t t h e A t t a b , a n d c l i c k t h e r a d i o b u t t o n f o r A l l c o v a r i a t e s a t t h e i r m e a n s i n t h e s a m p l e .
twoway (scatter food_exp income) (lfit food_exp income), ytitle(makanan) ylabel(0(100)600) xtitle(pendapatan) xlabel(0(5)35) title(Latihan)
11
. estat vce
Covariance matrix of coefficients of regress model e(V) | income _cons
---+--- income | 4.3817522 _cons | -85.903157 1884.4423
. describe
Contains data from /Users/purwantowidodo/Desktop/Using Stata/Data Principle Econo/utown.dta
obs: 1,000
vars: 6 2 May 2020 14:01 size: 20,000
--- ---
storage display value
variable name type format label variable label
--- ---
price double %10.0g price sqft double %10.0g sqft age byte %10.0g age utown byte %10.0g utown pool byte %10.0g pool fplace byte %10.0g fplace
--- ---
Sorted by:
REGRESSION USING INDICATOR VARIABLES . histogram price if utown==1
(bin=22, start=191.57, width=6.9830455)
. histogram price if utown==1, percent (bin=22, start=191.57, width=6.9830455)
. histogram price if utown==0, percent (bin=21, start=134.316, width=6.793381)
. regress price sqft i.utown
price=β
o+ β
1sqft +β
2Dummy (utown)
Source | SS df MS Number of obs = 1,000 ---+--- F(2, 997) = 3192.10 Model | 1538226.51 2 769113.255 Prob > F = 0.0000 Residual | 240219.632 997 240.942459 R-squared = 0.8649 ---+--- Adj R-squared = 0.8647 Total | 1778446.14 999 1780.22637 Root MSE = 15.522 --- price | Coef. Std. Err. t P>|t| [95% Conf. Interval]
---+--- sqft | 8.355663 .16832 49.64 0.000 8.025361 8.685965 1.utown | 60.36903 .9826958 61.43 0.000 58.44064 62.29742 _cons | 5.68086 4.290153 1.32 0.186 -2.737905 14.09963 --- price = 5.68086 + 8.355663sqft + 60.36903 (1)
price = 5.68086 + 8.355663sqft (2) . regress price i.utown#c.sqft
Source | SS df MS Number of obs = 1,000 ---+--- F(2, 997) = 3205.40 Model | 1539088.69 2 769544.343 Prob > F = 0.0000 Residual | 239357.455 997 240.077688 R-squared = 0.8654 ---+--- Adj R-squared = 0.8651 Total | 1778446.14 999 1780.22637 Root MSE = 15.494 --- price | Coef. Std. Err. t P>|t| [95% Conf. Interval]
---+--- utown#c.sqft |
0 | 7.07061 .1697921 41.64 0.000 6.737419 7.403801 1 | 9.45138 .1685436 56.08 0.000 9.12064 9.782121 |
_cons | 38.17748 4.264394 8.95 0.000 29.80926 46.54569 ---
price=β
o+ β
1(sqft∗Dummy (utown))
Price = 38.17748 + 9.45138sqft . summa
Variable | Obs Mean Std. Dev. Min Max ---+--- food_exp | 40 283.5735 112.6752 109.71 587.66 income | 40 19.60475 6.847773 3.69 33.4 . regress food_exp income
Source | SS df MS Number of obs = 40 ---+--- F(1, 38) = 23.79 Model | 190626.984 1 190626.984 Prob > F = 0.0000 Residual | 304505.176 38 8013.2941 R-squared = 0.3850 ---+--- Adj R-squared = 0.3688 Total | 495132.16 39 12695.6964 Root MSE = 89.517 --- food_exp | Coef. Std. Err. t P>|t| [95% Conf. Interval]
---+--- income | 10.20964 2.093264 4.88 0.000 5.972052 14.44723 _cons | 83.416 43.41016 1.92 0.062 -4.463279 171.2953 --- .Interval confidence
1 0 4 C h a p t e r 3
T h e i n t e r v a l e s t i m a t e s a r e c o m p u t e d a s
C o e f . ± t - c r i t i c a l * S t d . E r r .T h e v a l u e s o f t h e c o e f f i c i e n t s a r e g i v e n , a s a r e t h e s t a n d a r d e r r o r s . T h e r e m a i n i n g i n g r e d i e n t i s t h e t - c r i t i c a l v a l u e . T h i s c a n b e f o u n d i n T a b l e 2 o f P r i n c i p l e s o f E c o n o m e t r i c s , o r u s i n g S t a t a , a s w e n o w s h o w .
3 .1 .1 C r itic a l v a lu e s f r o m th e t- d is tr ib u tio n
W e c a n u s e S t a t a t o c o m p u t e c r i t i c a l v a l u e s o f m a n y p r o b a b i l i t y d i s t r i b u t i o n s , w h i c h i s v e r y h a n d y i n m a n y c o n t e x t s . C r i t i c a l v a l u e s a r e c r e a t e d a s s c a l a r s i n S t a t a a n d c a r r y t h e g e n e r a l p r e f i x
i n v
, i n d i c a t i n g t h a t t h e y a r e “ i n v e r s e ” f u n c t i o n s . T o r e c a l l t h e c o m m a n d f o r a p a r t i c u l a r s c a l a r v a l u e e n t e r
h e l p s c a l a r
C l i c k o n
d e f i n ei n t h e V i e w e r b o x i f y o u w i s h t o u s e a d i a l o g b o x . U s i n g t h e E x p r e s s i o n b u i l d e r ( s e e S e c t i o n 1 . 1 2 . 8 i n t h i s m a n u a l ) b o x l o c a t e
i n v t t a i l ( ), d o u b l e c l i c k , a n d f i l l i n t h e d e g r e e s o f f r e e d o m N í 2 = 3 8 a n d t h e a m o u n t o f t h e p r o b a b i l i t y i n t h e u p p e r t a i l o f t h e t - d i s t r i b u t i o n r e q u i r e d f o r a 9 5 % i n t e r v a l e s t i m a t e : 2 . 5 % o f t h e p r o b a b i l i t y i n t h e u p p e r t a i l d e f i n e s t h e 9 7 . 5 p e r c e n t i l e o f t h e t - d i s t r i b u t i o n . C l i c k O K .
I n t h e s c a l a r d e f i n e b o x w e n o w h a v e
Uji hipotesis
1 0 6 C h a p t e r 3
d i " b e t a 2 9 5 % i n t e r v a l e s t i ma t e i s " l b 2 " , " u b 2
p r o d u c i n g
3 .2 H Y P O T H E S IS T E S T S
T h e t - s t a t i s t i c s u s e d f o r h y p o t h e s i s t e s t s a b o u t t h e p a r a m e t e r s c a n b e c o m p u t e d u s i n g a c a l c u l a t o r f r o m t h e r e g r e s s i o n o u t p u t a n d a t - c r i t i c a l v a l u e f r o m a s t a t i s t i c a l t a b l e . H o w e v e r i n t h i s s e c t i o n w e w i l l c o m p u t e t h e t e s t s t a t i s t i c v a l u e s , c r i t i c a l v a l u e s a n d p - v a l u e s u s i n g S t a t a . A s a n e x a m p l e w e w i l l c o n t i n u e w i t h t h e f o o d e x p e n d i t u r e r e g r e s s i o n m o d e l .
3 .2 .1 R ig h t- ta il te s t o f s ig n ific a n c e
T o t e s t t h e n u l l h y p o t h e s i s H
0: E
20 a g a i n s t t h e a l t e r n a t i v e h y p o t h e s i s H
1: E !
20 . W e c a n c o n s t r u c t a n d d i s p l a y t h e t - s t a t i s t i c v a l u e a n d c r i t i c a l v a l u e u s i n g
s c a l a r t s t a t 0 = _ b [ i n c o me ] / _ s e [ i n c o me ] d i " t s t a t i s t i c f o r Ho : b e t a 2 =0 = " t s t a t 0 d i " t ( 3 8 ) 9 5 t h p e r c e n t i l e = " i n v t t a i l ( 3 8 , 0 . 0 5 )
N o t e t h a t t h e c r i t i c a l v a l u e c o m e s f r o m t h e r i g h t t a i l o f t h e t - d i s t r i b u t i o n a n d w e u s e t h e
i n v t t a i lc o m m a n d t o f i n d t h e c r i t i c a l v a l u e . T h e t - s t a t i s t i c v a l u e s f o r t h e n u l l h y p o t h e s i s t h a t t h e c o e f f i c i e n t s a r e z e r o a r e a u t o m a t i c a l l y p r o d u c e d b y S t a t a w h e n a r e g r e s s i o n m o d e l i s e s t i m a t e d i n t h e c o l u m n l a b e l e d “ t ” .
b e t a 2 9 5 % i n t e r v a l e s t i ma t e i s 5 . 9 7 2 0 5 2 5 , 1 4 . 4 4 7 2 3 3 . d i " b e t a 2 9 5 % i n t e r v a l e s t i ma t e i s " l b 2 " , " u b 2
t ( 3 8 ) 9 5 t h p e r c e n t i l e = 1 . 6 8 5 9 5 4 5
. d i " t ( 3 8 ) 9 5 t h p e r c e n t i l e = " i n v t t a i l ( 3 8 , 0 . 0 5 ) t s t a t i s t i c f o r H o : b e t a 2 = 0 = 4 . 8 7 7 3 8 0 6
. d i " t s t a t i s t i c f o r H o : b e t a 2 = 0 = " t s t a t 0 . s c a l a r t s t a t 0 = _ b [ i n c o me ] / _ s e [ i n c o me ]
Pengujian variable
. lincom income = menggunkana t distribution ( 1) income = 0
--- food_exp | Coef. Std. Err. t P>|t| [95% Conf. Interval]
---+--- (1) | 10.20964 2.093264 4.88 0.000 5.972052 14.44723 ---
. lincom income - 15 ( 1) income = 15
--- food_exp | Coef. Std. Err. t P>|t| [95% Conf. Interval]
---+--- (1) | -4.790357 2.093264 -2.29 0.028 -9.027948 -.5527666 ---
Pengujian 2 variabel
15
. lincom income -_cons ( 1) income - _cons = 0
--- food_exp | Coef. Std. Err. t P>|t| [95% Conf. Interval]
---+--- (1) | -73.20636 45.39417 -1.61 0.115 -165.102 18.68933 --- . lincom income +_cons -1
( 1) income + _cons = 1
--- food_exp | Coef. Std. Err. t P>|t| [95% Conf. Interval]
---+--- (1) | 92.62564 41.43691 2.24 0.031 8.741002 176.5103 --- Menggunakan distribusi F
test
. test advert ( 1) advert = 0
F( 1, 72) = 7.43 Prob > F = 0.0080 . . test advert = 2
( 1) advert = 2
F( 1, 72) = 0.04 Prob > F = 0.8412