0% found this document useful (0 votes)
39 views2 pages

Creating A Set of Dummy Variables To Represent A Categorical Variable

This document describes two methods for creating dummy variables to represent a categorical variable: 1) The labor intensive method of manually generating and replacing dummy variables for each category. 2) A much easier tabulate command that generates dummy variables for each category in one step.

Uploaded by

morry123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views2 pages

Creating A Set of Dummy Variables To Represent A Categorical Variable

This document describes two methods for creating dummy variables to represent a categorical variable: 1) The labor intensive method of manually generating and replacing dummy variables for each category. 2) A much easier tabulate command that generates dummy variables for each category in one step.

Uploaded by

morry123
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Creating a set of dummy variables to represent a categorical variable

The labor intensive way:

I. GENERATE REP1=1 IF REPAIR==1

II. REPLACE REP1=0 IF REPAIR!=1 & REPAIR!=.

III. GENERATE REP2=1 IF REPAIR==2

IV. REPLACE REP1=0 IF REPAIR!=2 & REPAIR!=.

V. GENERATE REP3=1 IF REPAIR==3

VI. REPLACE REP3=0 IF REPAIR!=3 & REPAIR!=.

VII. GENERATE REP4=1 IF REPAIR==4

VIII. REPLACE REP1=0 IF REPAIR!=4 & REPAIR!=.

IX. GENERATE REP5=1 IF REPAIR==1

X. REPLACE REP5=0 IF REPAIR!=5 & REPAIR!=.

A much easier way to accomplish the same thing:

XI. TABULATE REPAIR, GEN(ALTREP)

Creating a set of dummy variables to represent a categorical variable

The labor intensive way:

generate rep1=1 if repair==1


replace rep1=0 if repair!=1 & repair!=.

generate rep2=1 if repair==2


replace rep1=0 if repair!=2 & repair!=.

generate rep3=1 if repair==3


replace rep3=0 if repair!=3 & repair!=.

generate rep4=1 if repair==4


2

replace rep1=0 if repair!=4 & repair!=.

generate rep5=1 if repair==1


replace rep5=0 if repair!=5 & repair!=.

A much easier way to accomplish the same thing:

tabulate repair, gen(altrep)

You might also like