Reflection paper Applied Business Analytics

profileMerina24
PredictiveAnalyticsforBusinessStrategy_RegressionNotesforchapters5_6_7.pdf

Regression1 Regression analysis is one of the most frequently used optimization tools in business analytics.

The key benefits of using regression analysis are that it can:

1. Indicate if independent variables (IVs) have a significant relationship w/ a dependent variable

(DV).

2. Indicate the relative strength of different independent variables’ effects on a DV.

3. Make predictions.

Understanding Regression Analysis

Regression analysis is a way of fitting a “best” line through a series of observations.

With “best” line we mean that it is fitted in such a way that it minimizes the sum of squared differences

b/w the observations and the line itself.

Note: The “Best” line is not necessarily the true line if we have data issues or we fail to meet the

regression assumptions, in which case the line may be biased.

A two variable regression model is generally noted as follows:

𝑦𝑖 = 𝜇𝑦|𝑥 + 𝜀 = 𝑏0 + 𝑏1𝑥1𝑖 + 𝜀𝑖

1. 𝜇𝑦|𝑥 = 𝑏0 + 𝑏1𝑥1𝑖 is the mean value of the dependent variable 𝑦 when the value of the

independent variable is 𝑥.

2. 𝑏0 is the y-intercept. 𝑏0 is the mean value of 𝑦 when 𝑥 is equal to 0.

3. 𝑏1 is the slope. 𝑏1 is the change in the mean value of 𝑦 associated with a one-unit increase in 𝑥.

4. 𝜀 is an error term that describes the effects on 𝑦 of all factors other than the value of the

independent variable 𝑥.

Note: If we were to have more than 2 IVs, we would specify a multiple regression function with 𝑘 IVs as

𝑦𝑖 = 𝜇𝑦|𝑥 + 𝑒 = 𝑏0 + 𝑏1𝑥1𝑖 + ⋯ + 𝑏𝑘 𝑥𝑘𝑖 + 𝜀𝑖

We do not know the true values of the parameters 𝑏0 and 𝑏1, but we can use sample data to obtain point

estimates, which are denoted as �̂� and �̂�1.

The sample simple linear regression equation provides an estimate of the true regression line, also known

as the population regression function.

𝑦𝑖 = �̂�0 + �̂�1𝑥𝑖 + 𝑒𝑖

The predictions made by the best regression line are indicated by

�̂�𝑖 = �̂�0 + �̂�1𝑥𝑖

1 Notes adapted from “Predictive Analytics” by Prince, “A Concise Guide to Market Research,” by Sarstedt and Mooi , and “Multivariate Data Analysis” by Hair et al.

where �̂�𝑖 is the predicted value of y for the i th observation, �̂� is the sample estimate of the 𝑦-intercept, �̂�1

is the sample estimate of the slope coefficient, and 𝑥𝑖 is the value of 𝑥 for the i th observation (or person in

a study, for example).

Hence, the error for any observation (or sample, or unit of analysis, usually individuals in the social

sciences) can be solved for as

𝑦𝑖 − �̂�𝑖 = 𝑒𝑖

The error term (or residual) is the distance b/w each observation and the best fitting line.

This can be expressed graphically as follows:

Again, the error is the difference b/w the regression line, or the “prediction” equation based on sample

information, and the actual observation.

Data Requirements for Regression Analysis

Sample Size

The first data requirement is that we need a sufficiently large sample. Although you can conduct a

“power analysis” to determine sample size, you can also use rules of thumb.

If you want to test for whether parameter coefficients have a statistically significant effect on the DV, you

need a sample equal to 104 + 𝑘, where 𝑘 is equal to the number of IVs.

Variation

Also, in regression, both the DV and the IVs must vary.

Scale Type of DV

Next, the DV needs to be interval or ratio scaled.

If data are not interval or ratio scaled, alternative types of regression models need to be used – e.g.,

logistic regression if the DV is binary (we will study logistic regression later in our course).

Collinearity

The last data requirement is that little or no collinearity is present. Collinearity is a data issue that arises

if 2 IVs are highly correlated.

Multicollinearity occurs if more than 2 IVs are highly correlated.

Collinearity is relatively easy to detect by calculating the tolerance or variance inflation factor (VIF).

A tolerance below 0.10 indicates that multicollinearity is a problem. Since VIF is just the reciprocal of

thee tolerance, a value above 10 indicates collinearity issues.

What can be done about multicollinearity? Two main options exist:

1. Use factor analysis, and advanced topic not discussed in our text.

2. Re-specify the regression model by removing highly correlated variables. If you do this, beware

of omitted variable bias.

We can assess whether multicollinearity is a problem using regression postestimation commands in Stata.

As a quick example, suppose we are interested in regressing supermarket sales per week on the average

price level (Price) and an index of promotional activities (Promotion).

These data are contained in our “regress_sales.dta” dataset.

. use regress_sales, clear

. regress Sales Price Promotion

. estat vif

Since the VIFs are < 10, multicollinearity is not a problem.

Specify and Estimate the Regression Model

For a basic regression model, we need to specify the DV and the IVs. IVs are usually selected based on

what the client wants to know or past research findings (do not forget to do a literature review).

As a business researcher, you want to select variables that are meaningful for the decision-making process

– i.e., regression results must be used to inform specific decisions and/or problem areas.

Surveys should be constructed w/ a question that taps into the relevant outcome, or dependent variable

(DV), questions that measure the drivers of the outcome, or independent variables (IVs), and

demographic items that must be controlled for to prevent bias.

Once we know which variables that we explore in an analysis, we need to specify if all of them should be

used.

You can either

1. Choose the IVs yourself, or

2. Incorporate a stepwise procedure.

Unless you are doing purely exploratory data analysis, chose the 1st option.

Stepwise methods often result in adding variables that are only significant by chance.

Further, if data are missing, stepwise procedures often result in finding highly significant models that only

use a small number of observations from the total number of available observations.

In this case, the regression model fits a small set of the data well but not the entire data or population.

As previously stated, we can estimate the population regression equation by applying an optimization

technique called ordinary least squares (OLS) to the sample simple linear regression function.

𝑦𝑖 = �̂�0 + �̂�1𝑥𝑖 + 𝑒𝑖

�̂�0 and �̂�1 are obtained by finding the values of �̂�0 and �̂�1 that minimize the sum of the squared errors, or

the differences between the actual values 𝑦𝑖 and the predicted values �̂�𝑖 .

Hence, the predicted values can be solved for as

�̂�𝑖 = �̂�0 + �̂�1𝑥𝑖

min SSE = min ∑ 𝑒𝑖 2

𝑛

𝑖=1

= min ∑(𝑦𝑖 − �̂�𝑖 ) 2 =

𝑛

𝑖=1

min ∑[𝑦𝑖 − (�̂�0 + �̂�1𝑥𝑖 )] 2

𝑛

𝑖=1

The least squares point estimates can be solved for using the “normal” equations (don’t worry about

having to solve for this by hand, by the way):

�̂�1 = 𝑆𝑆𝑥𝑦

𝑆𝑆𝑥 , where

𝑆𝑆𝑥𝑦 = ∑(𝑥𝑖 − �̅�)

𝑛

𝑖=1

(𝑦𝑖 − �̅�) = ∑ 𝑥𝑖 𝑦𝑖 − (∑ 𝑥𝑖

𝑛 𝑖=1 ) ∑ 𝑦𝑖

𝑛 𝑖=1

𝑛

𝑛

𝑖=1

and

𝑆𝑆𝑥𝑥 = ∑(𝑥𝑖 − �̅�) 2 = ∑ 𝑥𝑖

2 − (∑ 𝑥𝑖

𝑛 𝑖=1 )

2

𝑛

𝑛

𝑖=1

𝑛

𝑖=1

or

�̂�1 = ∑ (𝑥𝑖 − �̅�)(𝑦𝑖 − �̅�)

𝑛 𝑖=1

(𝑥𝑖 − �̅�) 2

As you can see, this is just the covariance of 𝑦 and 𝑥 divided by the variance of 𝑥.

Once we have solved for �̂�1, it is straightforward to get �̂�0

�̂�0 = �̅� − �̂�1�̅�

As you can see by looking at the formulas above, we can use sample information to solve for �̂�0 and �̂�1,

or to solve for our sample estimates of the population parameters 𝑏0 and 𝑏1.

Just like we did in evaluating hypotheses about the mean, we can construct a sampling distribution of �̂�0

and �̂�1 to determine whether the sample value is different than the hypothesized value.

In other words, in regression analysis, we can calculate whether 𝑏0 and 𝑏1 differ significantly from zero by using a t-test.

Test the Assumptions of Regression Analysis

Five regression assumptions are required to provide valid regression results. If the regression

assumptions are satisfied, the ordinary least squares estimation procedure provides the best linear

unbiased estimates – i.e., they are BLUE.

Assumption 1. First, the regression model should be linear in the parameters – i.e., model parameters are

raised to a coefficient of one. That said, we can use regression to model nonlinear relations.

Here is an example of a linear function

𝑦𝑖 = 𝑏0 + 𝑏1𝑥1𝑖 + 𝜀𝑖

An example of a nonlinear function is

𝑦𝑖 = 𝑏0 + 𝑏1 2𝑥1𝑖 + 𝜀𝑖

However, we can estimate the following nonlinear model since it is still linear in the parameters

𝑦𝑖 = 𝑏0 + 𝑏1𝑥1𝑖 2 + 𝜀𝑖

Assumption 2. The 2nd assumption is that the expected mean error of the regression model is zero. In

other words, at any given value of 𝑥, the population of potential error term values has a mean equal to zero (draw).

Assumption 3. The variance of error terms is constant (homoscedasticity). Specifically, the populations

of potential error term values corresponding to different values of x have equal variances σ2 (draw).

Let us discuss heteroscedasticity in the context of an example modified from “Practical Econometrics,”

by Hilmer and Hilmer.

A sample of 73,046 mortgage applications filed in the state of CA were collected from the Home

Mortgage Disclosure Act database.

. import excel using "California_Home_Mortgage_Application_Data_Master.xlsx", sheet(Master)

firstrow clear

Note: The command above must be inputted into Stata’s command prompt in one line (versus two as

above).

. describe

. summarize

The summary stats suggest that there is wide variation in both the requested loan amount and applicant

income.

Since we are interested in predicting the loan amount as a function of income, both measured in dollars,

construct a scatter plot of LOANAMOUNT on Income.

. scatter LOANAMOUNT Income

The fact that requested loan amounts fan out as observed applicant incomes increase suggests that these

data may be heteroscedastic (it can be shown that the distribution of DV values are equal to the

distribution of the estimated error terms).

After we run a regression of LOANAMOUNT (DV) on Income (IV), we can scatter the predicted

residuals to further assess the possibility of heteroscedasticity.

. regress LOANAMOUNT Income

. predict resids, residuals

. scatter resids Income

As you can see, the variance of the error terms is not constant.

Before correcting for the problem of heteroscedasticity, we would run a variety of “formal” tests to detect

heteroskedasticity.

Note: In the presence of homoscedasticity, OLS estimators are still linear, unbiased, and consistent, they

are just not efficient – i.e., they no longer have minimum variance.

Again, we can solve the problem using WLS or White’s robust standard errors, both of which are easy to

implement in Stata.

When we run WLS in Stata, we simply use the variable that we think causes the error variance not to be

constant and “weight” the results by this variable.

Assumption 4: The error terms are independent (no autocorrelation). Any one value of the error term is

statistically independent of any other value of the error term.

In short, autocorrelation exists when the error term in a given time period 𝑡 is in some way correlated w/

the error term from a previous time period, say 𝑡 − 1.

If we relax the assumption of no autocorrelation for OLS, the least squares estimators are still linear,

unbiased, and consistent.

However, they are no longer efficient – i.e., they no longer have minimum variance. Further, the

estimated variances of OLS estimators are biased.

Autocorrelation is usually only a problem in time series data – i.e., data that vary over time. Further, it

can be positive or negative.

Positive autocorrelation exists when above-average errors tend to follow other above-average errors and

below-average errors tend to follow other below-average errors.

In negative autocorrelation, above-average errors tend to follow below-average errors and below-average

errors tend to follow above-average errors.

If we suspect the existence of autocorrelation, we can start w/ a visual examination of the error terms.

As w/ the problem of heteroskedasticity, we can “fix” the problem of autocorrelation using robust

standard errors or other techniques that are easy to implement in Stata.

Assumption 5: At any given value of 𝑥, the population of potential error terms is normally distributed. If this is not the case, the t-values may be incorrect.

However, even if the errors of the regression model are not normally distributed, the regression model

still provides good estimates of the coefficients.

We can check for normally distributed errors by 1) conducting a graphical analysis of the residuals or 2)

by performing a formal test.

Let us do an example w/ our sales data where “Sales” is measured as weekly sales in US dollars, “Price”

is measured as the price of the product in dollars, and “Promotion” is measured as an index of

promotional activities for which higher values are associated w/ higher levels of promotional activities.

. use regress_sales, clear

. describe

. summarize

. regress Sales Price Promotion

. predict resids, residuals

. hist resids, bin(8)

As you can see, the residuals appear to be approximately normally distributed.

There are 3 additional potential sources of bias that we must be mindful of when doing regression

analysis:

1. Using the incorrect functional form – this occurs when we use a linear model to estimate a

nonlinear model (remember, we can estimate nonlinear models are long as our model is linear in

the parameters)

2. Omitted variable bias (OVB) – this occurs when we leave an important IV or IVs out of a study

3. Measurement error in the IV – this occurs when the IV or IVs are measured w/ too much error

Effects of Individual Variables

If the regression assumptions are satisfied and SSE is the sum of squared residuals (simply the sum of the

squares of the differences b/w the actual 𝑦𝑖 values and the predicted �̂�𝑖 values (as shown below), then

1. The point estimate of σ2 is the mean square error

𝑠2 = 𝑆𝑆𝐸

𝑛 − 2

2. The point estimate of σ is the standard error

𝑠 = √ 𝑆𝑆𝐸

𝑛 − 2

Again, the sum of squared residuals can be solved for as

𝑆𝑆𝐸 = ∑(𝑦𝑖 − �̂�𝑖 ) 2 where �̂�𝑖 = �̂�0 + �̂�1𝑥𝑖

𝑛

𝑖=1

Note: We subtract 𝑛 − 2 to get the degrees of freedom in the denominator of our point estimate of the

mean square error and our point estimate of the standard error since we use sample data to estimate both

the intercept coefficient and the slope coefficient.

Given our regression assumptions, �̂�0 and �̂�1 are often referred to as the best linear unbiased estimators – they are the most efficient, or the most tightly distributed, estimators whose means equal the true values.

To assess whether the estimated effect of 𝑥 on 𝑦 is statistically significant, we test the following null against the alternate hypothesis:

𝐻0: 𝑏1 = 0

𝐻1: 𝑏1 ≠ 0

Since the least squares estimators are unbiased estimators of the true values, if we observe a point

estimate far from zero, we have statistical evidence that its value is different from zero.

That is, we have statistical evidence that 𝑥 has an effect on 𝑦.

If we took repeated samples of 𝑛 observations of 𝑦 and 𝑥 and solved for �̂�1 each time, the population of

all possible values of �̂�1 is normally distributed with a mean of 𝑏 and a standard deviation of

𝜎�̂�1 = 𝜎

√𝑆𝑆𝑥𝑥

Remember, the standard error 𝑠 is the point estimate of 𝜎, so it follows that a point estimate of 𝜎�̂�1 is

𝑠�̂�1 = 𝑠

√𝑆𝑆𝑥𝑥

which is called the standard error of the estimate �̂�1.

Further, if the regression assumptions hold, the population of all values of �̂�1 −𝑏1

𝑠𝑏1 has a t-distribution with

𝑛 − 2 degrees of freedom.

It follows that if the null hypothesis is true, the population of all possible values of the test statistic 𝑡 =

�̂�1/𝑠�̂�1 has a t-distribution with a mean equal to zero and 𝑛 − 2 degrees of freedom.

We can reject 𝐻0: 𝑏1 = 0 in favor of the alternative hypothesis at significance level 𝛼 (that is, by setting

the probability of a Type 1 error equal to 𝛼) if the calculated t-statistic is greater than the critical t-value,

or if the corresponding p-value is less than 𝛼.

Null Hypothesis Alternative Hypothesis Rejection Point

Condition

p-Value

𝐻0: 𝑏1 = 0 𝐻1: 𝑏1 ≠ 0 |𝑡| > 𝑡[∝/2] (𝑛−2)

Twice the area under

the t curve to the right

of |𝑡| 𝐻0: 𝑏1 ≤ 0 𝐻1: 𝑏1 > 0 𝑡 > 𝑡[∝]

(𝑛−2) The area under the t-

curve to the right of t

𝐻0: 𝑏1 ≥ 0 𝐻1: 𝑏1 < 0 𝑡 < −𝑡[∝] (𝑛−2)

The area under the t-

curve to the left of t

Example:

Suppose we are interested in whether sales are a function of an index of promotional activities. We can

estimate this model in Stata by using the command below.

. regress Sales Promotion

Q: Use the output above to determine whether our point estimate �̂�1 of 𝑏1 is statistically significant. Do both a one-sided and two-sided test.

For each provide the calculated t-value, the critical t-value, and the p-value.

In addition to testing the significance of the slope, it is often useful to calculate a confidence interval for

𝑏1.

If the regression assumptions hold, a 100(1 − 𝛼)% confidence interval for the true slope 𝑏1 is

[�̂�1 ± 𝑡[∝/2] (𝑛−2)

∙ 𝑠�̂�1 ]

Q: Use the results above to reproduce the interval estimate for 𝑏1. Since the hypothesized value is not included in the confidence interval, we can reject the null.

The interval says we are 95% confident that if promotional activities increases by one unit, the increase in

sales will be between $33.70 and $75.48.

Overall Model Fit

Using a predictor variable in a regression allows us to move from the mean as our prediction of 𝑦 to �̂� as

our prediction of 𝑦.

Using the predictor variable 𝑥 decreases the prediction error in predicting 𝑦𝑖 from (𝑦𝑖 − �̅�) to (𝑦𝑖 − �̂�𝑖 ),

or by an amount equal to (�̂�𝑖 − �̅�).

Illustrate on the board.

It can be shown that

∑(𝑦𝑖 − �̅�) 2 − ∑(𝑦𝑖 − �̂�𝑖 )

2 = ∑(�̂�𝑖 − �̅�) 2

The first term is the total variation in 𝑦, the second term is the unexplained variation in 𝑦 (SSE), and the

last term is the explained variation in 𝑦 (SSR).

Thus, total variation – unexplained variation = explained variation, or total variation = unexplained

variation + explained variation.

That is

𝑇𝑆𝑆 = 𝑆𝑆𝐸 + 𝑆𝑆𝑅

_cons 2463.9 582.4774 4.23 0.000 1270.75 3657.051

Promotion 54.5911 10.19705 5.35 0.000 33.7034 75.47881

Sales Coef. Std. Err. t P>|t| [95% Conf. Interval]

Total 218804418 29 7544979.91 Root MSE = 1965.1

Adj R-squared = 0.4882

Residual 108125495 28 3861624.82 R-squared = 0.5058

Model 110678923 1 110678923 Prob > F = 0.0000

F(1, 28) = 28.66

Source SS df MS Number of obs = 30

where SSR is known as the regression sum of squares, or the explained variation. We’re interested in the

percentage of the total variation that we can explain using our regression model, or SSR/TSS.

𝑇𝑆𝑆 − 𝑆𝑆𝐸 = 𝑆𝑆𝑅

1 − 𝑆𝑆𝐸

𝑇𝑆𝑆 =

𝑆𝑆𝑅

𝑇𝑆𝑆

SSR/TSS is known as the simple coefficient of determination, or R2.

Example:

Q: Solve for R2 using the regression output above.

THE CORRELATION COEFFICIENT, r

The simple correlation coefficient between 𝑦 and 𝑥, denoted by 𝑟, is

𝑟 = +√𝑟2 if �̂�1 is positive and 𝑟 = −√𝑟 2 if �̂�1 is negative

Since R 2 is always between 0 and 1, the correlation coefficient r is between -1 and 1.

AN F-TEST FOR THE MODEL

We can use the F-statistic to test the statistical significance of the model as a whole.

If the regression assumptions hold, the calculated F-statistic can be solved for as

𝐹(model) = Explained variation/𝑘

(unexplained variation)/(𝑛 − 2)

where k is equal to the number of IVs (in our example, one).

Also, define the p-value related to F(model) to be the area under the curve of the F-distribution to the

right of the calculated F-statistic.

We can reject the 𝐻0: 𝑏1 = 0 in favor of 𝐻𝑎 : 𝑏1 ≠ 0 at level of significance 𝛼 if either of the following conditions hold:

1. F(model) > 𝐹[∝]

2. p-value < α

Here the critical F-value, or 𝐹[∝] is based on 1 numerator and 𝑛 − 2 denominator degrees of freedom.

We can easily extend our analysis to include more than one IV. For example

. regress Sales Promotion Price

When we add another variable, we must tweak our interpretation of the effect of a particular IV on the

DV to consider the fact that we have controlled for yet another IV.

In the case of our index of promotional activities, if we increase promotion activities by one unit, sales

will increase by $42.29 holding the value of Price constant.

In multiple regression, we follow the same approach to hypothesis testing, solving for the coefficient of

determination, and solving for the calculated F statistic as we did in simple regression.

Validate the Regression Model

After we have checked for the assumptions of regression analysis and interpreted the results, we need to

check for the stability of the regression model.

We can check for the stability of the regression model in several ways:

1. We can split the sample into two parts and run the regression model on each subset of data.

2. We can cross-validate our model using a new dataset.

3. We can assess the stability of our model by after adding additional variables.

Use the Regression Model

Finally, we use regression analysis for two main purposes:

1. To explain the “drivers” of DV under analysis (we have already done this by assessing the

statistical significance of IVs) and

2. To make predictions.

Predicted values in Stata can be obtained using the commands below.

. regress Sales Promotion

. predict pSales

We can use the following command to compare our regression model for sales given promotional

activities (the red line) and the actual scatterplot between sales and promotional activities (blue dots).

. scatter Sales pSales Promotion, connect(. l)

_cons 30227.33 16853.85 1.79 0.084 -4353.905 64808.57

Price -25138.29 15251.66 -1.65 0.111 -56432.1 6155.53

Promotion 42.29479 12.39472 3.41 0.002 16.86293 67.72666

Sales Coef. Std. Err. t P>|t| [95% Conf. Interval]

Total 218804418 29 7544979.91 Root MSE = 1907.5

Adj R-squared = 0.5178

Residual 98240756.3 27 3638546.53 R-squared = 0.5510

Model 120563661 2 60281830.6 Prob > F = 0.0000

F(2, 27) = 16.57

Source SS df MS Number of obs = 30

Now, let us estimate our multiple regression model. Does including both variables make a difference?

Yes!

. regress Sales Promotion Price

. predict PSales

Dummy Variable Regression Models for Treatment Effects

Frequently in regression analysis the DV is influenced by variables that are qualitative in nature.

Qualitative variables indicate the presence or absence of a quality, attribute, treatment, etc., such as

whether a patient in a hospital gets a treatment.

One method of “quantifying” these attributes is by constructing variables that take on values of 0 or 1, 0

indicating the absence of an attribute and 1 indicating the presence of that attribute.

For example, 1 may indicate that a person was given a healthcare intervention, or treatment, and 0 may

designate a person who did not get the treatment.

Regression models that contains only dummy variables are called ANOVA models. Consider the

following example of an ANOVA model:

𝑦𝑖 = 𝑏0 + 𝑏1𝐷𝑖 + 𝜀𝑖

where Y = annual expenditure on food

𝐷𝑖 = 1 if treatment, 0 otherwise

If the disturbances satisfy the usual assumptions of the CLRM, the mean outcome for those who do not

receive the treatment can be solved for as

𝐸(𝑦𝑖 |𝐷𝑖 = 0) = 𝑏0 + 𝑏10

= 𝑏0

The mean outcome for those who did get the treatment can be solved for as

𝐸(𝑌𝑖 |𝐷𝑖 = 1) = 𝑏0 + 𝑏1(1)

= 𝑏0 + 𝑏1

𝑏1 is often referred to as the differential intercept coefficient because it tells by how much the value of the intercept term differs between the two categories, or how much the “outcome” varies by “treatment.”

A test of the null hypothesis that there is no difference in the mean outcome of the experimental (those

who receive the treatment) and control groups (those who do not receive the treatment) can be made using

OLS and using the t test to find out if 𝑏2 is statistically significant.

Let us do an example using the “treatment” data.

The treatment data contains the dependent variable (DV) “outcome” measured as a patient’s viral load per

unit of blood and the independent variable (IV) “treatment” measured as 1 for those patients who get an

antiviral medication and 0 for patients who do not get an antiviral treatment.

Let us import these data into Stata to estimate the model above.

. use treatment, clear

. describe

. summarize

. list

Regressing the outcome of the DV (outcome) on whether a person gets the treatment (treatment) on gives

the following results:

The mean outcome (or average viral load per unit of blood) for those who do not get the treatment is

equal to 3176.83.

The mean outcome for those who do get the treatment is equal to = 3176.83 – 503.16 = 2673.66.

Q: Are the results statistically significant?

Compare your regression results to the average outcome by treatment.

. sort treatment

_cons 3176.833 233.0446 13.63 0.000 2657.578 3696.089

treatment -503.1667 329.5749 -1.53 0.158 -1237.505 231.1719

outcome Coef. Std. Err. t P>|t| [95% Conf. Interval]

Total 4018118.25 11 365283.477 Root MSE = 570.84

Adj R-squared = 0.1079

Residual 3258588.17 10 325858.817 R-squared = 0.1890

Model 759530.083 1 759530.083 Prob > F = 0.1578

F(1, 10) = 2.33

Source SS df MS Number of obs = 12

. regress outcome treatment

. by treatment: summarize outcome

As you can see, the dummy variable is simply a device to find out if the two mean values are different.

Q: Since we have two categories, whether a person gets the treatment and otherwise, why not assign two

dummy variables?

If categorical, or dummy, variable has m categories, introduce only (m-1) dummy variables. The

reference category that has zeros for all dummies falls in the intercept.

Finally, these results are nearly identical to those obtained using a two-sample t-test, or the differences in

means test we did in chapter 3! Notice the calculated t-value below is identical to t-value on the treatment

variable above.

. ttest outcome, by(treatment)

Pr(T < t) = 0.9211 Pr(|T| > |t|) = 0.1578 Pr(T > t) = 0.0789

Ha: diff < 0 Ha: diff != 0 Ha: diff > 0

Ho: diff = 0 degrees of freedom = 10

diff = mean(0) - mean(1) t = 1.5267

diff 503.1667 329.5749 -231.1719 1237.505

combined 12 2925.25 174.4715 604.3869 2541.241 3309.259

1 6 2673.667 193.1672 473.1611 2177.115 3170.219

0 6 3176.833 267.0319 654.0919 2490.406 3863.261

Group Obs Mean Std. Err. Std. Dev. [95% Conf. Interval]

Two-sample t test with equal variances

. ttest outcome, by(treatment)