Docsity

Data Management - Elementary Statistics - Exercise 1 | ECON 400, Assignments of Economic statistics

Toggle sidebar
bg1
Exercise No. 4: Data Management -- Part 1
replace
list
egen graph7 var, onewaygenerate
graph box var, over(.)histogram var, start(.)
width(.)
destring summarizedroplabel data helplabel definelabel variable describelabel valuesrename
Old Commands
Reviewed
New Stata
Commands
This exercise begins a semester-long exploration of data-handling facilities in Stata. You will
learn how to manipulate data, create new variables and data sets and create subsets of data that
can be subjected to independent analysis. This exercise covers roughly the first half of Chapter 2
(pages 13 - 38) of Statistics with Stata 9. You should study this section carefully in order to
understand the commands covered there that are not used in this exercise.
As you complete your exercise, be sure to include in the exercise the material requested in
paragraphs that are check-marked (9).
{Be sure to open a log and keep it for your records}
26 27 27 27 27 29 30 30 30 30 31 31 31 32 32 33 33 33 33 33 34 34 34 35 35 36
36 36 37 37 37 37 37 37 37 39 39 39 39 39 39 39 40 41 42 42 42 42 42 43 43 43
43 43 43 43 43 44 44 44 44 44 44 45 45 45 45 45 45 45 46 46 46 46 46 46 47 47
47 47 47 47 48 48 48 48 48 48 48 48 49 49 49 49 50 50 51 51 51 51 51 52 52 52
52 52 53 53 53 53 53 54 54 54 54 54 55 55 55 56 56 56 56 56 57 57 57 57 58 58
58 58 58 58 58 58 59 59 59 59 60 60 60 60 60 60 61 61 61 61 61 61 62 62 62 63
63 64 65 66 66 66 67 67 67 67 68 68 69 69 69 69 69 69 69 69 71 71 72 73 74 74
74 75 75 76 76 78 80 80 80 80 81 81 81 82 82 83 83 83 83 84 84 84 84 84 84 84
90 90 90 91 91 91 92 92 92 93 93 93 93 95 95
1. In the Sanitary District of Chicago, operating engineers are hired on the basis of a competitive
civil-service examination. In 1966, there were 223 applicants for 15 jobs. The exam was held on
March 12; the test scores are shown above, arranged in increasing order. On the basis of these
data, the examiners were charged with rigging the exam. Why? To answer this question, you
need to do the following:
{Enter the scores into a Stata spreadsheet. You want to put all 223 scores into a single
column. Note: Do not put a variable name in the first row of the spreadsheet. If you do,
Stata will think that you’re entering character (or “string”) data for that column. All the
numbers you type in after that will be treated as characters rather than numbers.
Economics 400: Professor Turchi
Page 1 of 6
pf3
pf4
pf5

Partial preview of the text

Download Data Management - Elementary Statistics - Exercise 1 | ECON 400 and more Assignments Economic statistics in PDF only on Docsity!

Exercise No. 4: Data Management -- Part 1

replace

list

egen

generate graph7 var, oneway

histogram var, start(.) graph box var, over(.) width(.)

destring

label data drop summarize

label variable label define help

rename label values describe

Old Commands Reviewed

New Stata Commands

This exercise begins a semester-long exploration of data-handling facilities in Stata. You will learn how to manipulate data, create new variables and data sets and create subsets of data that can be subjected to independent analysis. This exercise covers roughly the first half of Chapter 2 (pages 13 - 38) of Statistics with Stata 9. You should study this section carefully in order to understand the commands covered there that are not used in this exercise.

As you complete your exercise, be sure to include in the exercise the material requested in paragraphs that are check-marked ( 9 ).

{Be sure to open a log and keep it for your records}

26 27 27 27 27 29 30 30 30 30 31 31 31 32 32 33 33 33 33 33 34 34 34 35 35 36 36 36 37 37 37 37 37 37 37 39 39 39 39 39 39 39 40 41 42 42 42 42 42 43 43 43 43 43 43 43 43 44 44 44 44 44 44 45 45 45 45 45 45 45 46 46 46 46 46 46 47 47 47 47 47 47 48 48 48 48 48 48 48 48 49 49 49 49 50 50 51 51 51 51 51 52 52 52 52 52 53 53 53 53 53 54 54 54 54 54 55 55 55 56 56 56 56 56 57 57 57 57 58 58 58 58 58 58 58 58 59 59 59 59 60 60 60 60 60 60 61 61 61 61 61 61 62 62 62 63 63 64 65 66 66 66 67 67 67 67 68 68 69 69 69 69 69 69 69 69 71 71 72 73 74 74 74 75 75 76 76 78 80 80 80 80 81 81 81 82 82 83 83 83 83 84 84 84 84 84 84 84 90 90 90 91 91 91 92 92 92 93 93 93 93 95 95

  1. In the Sanitary District of Chicago, operating engineers are hired on the basis of a competitive civil-service examination. In 1966, there were 223 applicants for 15 jobs. The exam was held on March 12; the test scores are shown above, arranged in increasing order. On the basis of these data, the examiners were charged with rigging the exam. Why? To answer this question, you need to do the following:

{ Enter the scores into a Stata spreadsheet. You want to put all 223 scores into a single column. Note: Do not put a variable name in the first row of the spreadsheet. If you do, Stata will think that you’re entering character (or “string”) data for that column. All the numbers you type in after that will be treated as characters rather than numbers.

{ Rename the variable var1 to score and label the variable “Examination Score.” Use the following commands:

rename var1 score

label variable score “Examination Score”

{ You can also add information to the dataset, such as giving the dataset as a whole a name:

label data “Chicago Civil Service Exam”

9 Now describe the data set and paste the results into your exercise. Check the results of describe to determine if score really is being treated as numeric data rather than character data. Suppose looking at the column labelled “storage type” you don’t see “float” (or "byte" or "int" or "long" or "double") but “str21” or something else that starts with “str…”. What do you do then, start over and reenter all those numbers? No, you don’t have to do that. Instead, use either the command destring or the command generate newvar = real( score ) to create a numeric variable that you can work with. Go to help destring to use the easiest of two commands. Go to the end of the exercise to see a description of Stata data types.

{ How can you be sure that you did not make a mistake entering the data into Stata? (Hint: summarize score and see if your results match mine. If they do, fine. If not, find the error.) How would you insure the accuracy of your data if I hadn’t given you the information below?

Examination Score

Percentiles Smallest 1% 27 26 5% 31 27 10% 34 27 Obs 223 25% 43 27 Sum of Wgt. 223

50% 54 Mean 56. Largest Std. Dev. 17. 75% 68 93 90% 83 93 Variance 309. 95% 91 95 Skewness. 99% 93 95 Kurtosis 2.

9 Now, paste your (correct) summarize results into your exercise, so we can agree that we’re all working on the same data.

9 Now, let’s see if we can understand why the Civil Service Commission thought the examiners had rigged the exam. First, generate a oneway scatter diagram of the data and paste it into your exercise. 1 Second, generate a histogram using options start(25 ) and

(^1) See the command "graph7 ..." in the table on page 1. This is a Stata 7 command. Stata 10 graphics do not have a

one way scatter plot. Type "help graph7" in Stata to read more about this and other Stata 7 commands.

gen group=. replace group=1 if score < 30 replace group=2 if (score >29 & score < 43) replace group=3 if (score >42 & score <68) replace group=4 if (score >67 & score <90) replace group=5 if (score >89) label values group grouplbl label define grouplbl 1 "Cretin" 2 "Poor" 3 "Average" 4 "Good" 5 "Crook" graph box score, over(group)

The group of Stata commands above does the following things:

{ The generate command creates a variable named group and sets all of its values equal to “missing” (.).

{ The replace command replaces missing values in group with a “1” if the value of score is less than 30.

{ The next replace command replaces missing values in group with a “2” if the value of score is greater than 42 and less than 68. (Why have I chosen the end points that I have in these replace commands?)

{ Now, I label each value of variable group. The first label command sets up a location to store the labels for variable group. The second label command assigns a term to each value of group.

{ Finally, create a set of boxplots for the score variable separated by values of the group variable.

9 Paste the boxplot into your exercise.

{ Save your dataset.

  1. Now, let’s get a better idea of the true scores of the civil service applicants by getting rid of the crooks.

{ To do this, we can use the drop command as follows:

drop if group==

The command tells Stata to drop any observation that has a group value equal to 5.

{ Now, let’s list the lowest and highest values again:

list if (score <30 | score >80)

9 Paste the results of the list command into your exercise.

{ Finally let’s reduce the data set even further by getting rid of the cretins:

drop if group==

list if (score <35 | score >80)

{ Save the revised data set under a new name, say chicago_purged.

9 Finally summarize score now that it’s been purged of crooks and cretins, and paste your results into your exercise.