Describing the data
The sample of 6504 students in 7th to 12th
grade was taken from 80 high schools and 52 of their feeder schools from across
the United States. The ethnic composition was predominantly White (N=4038,
62.3%), Black (N=1483, 22.9%), Asian(N=212, 3.3%), Native American/Indian
(N=68, 1.0%), Other(N=362, 5.6%), and Multiple(N=322, 5.0%). The gender
composition was Female (N=3356, 51.6%), Male(N=3147, 48.4%) and one respondent
was unknown.
The school-based clustered sampling of the 132 school was
primarily conducted by Quality Education Data Inc. through the use of in-school
questionnaires, in-home interviews, school administrator questionnaires,
in-home interviews, and parent questionnaires.
Grade retention was drawn from the question “Were you ever
retained or held back a grade?” Students who responded “Yes” were then asked
which grade(s) they had been retained. The data was combined into one variable
and binned into four categories, “Never held back”, “Elementary School”, “Secondary”
and “Multiple”
Violence was drawn from three different questions with the
stem “How often the last 12 months have you…”
- · Gotten into a fight?
- · Pulled a knife or gun on someone?
- · Shot or stabbed someone?
Respondents who indicated any level of involvement in any of
the three categories were listed as positive for violence while all who had not
indicated any involvement were coded as negative for violence.
The age variable was calculated by subtracting the birth year from the year the survey was completed. Since the age variable itself is not used in the calculations, it's exact calculation isn't pertinent. Three respondents had a negative age calculation using this method and that data was disregarded.
Code to extract the above information (except pie chart)
- import pandas as pd
- import numpy as np
- import matplotlib.pyplot as plt
- filename="addhealth_pds.csv"
- data = pd.read_csv(filename, low_memory=False)
- data['H1GI6A']=data['H1GI6A'].replace(6, np.nan)
- data['H1GI6A']=data['H1GI6A'].replace(8, np.nan)
- data['H1GI6B']=data['H1GI6B'].replace(6, np.nan)
- data['H1GI6C']=data['H1GI6C'].replace(6, np.nan)
- data['H1GI6D']=data['H1GI6D'].replace(6, np.nan)
- data['H1GI6E']=data['H1GI6E'].replace(6, np.nan)
- data['H1GI6B']=data['H1GI6B'].replace(8, np.nan)
- data['H1GI6C']=data['H1GI6C'].replace(8, np.nan)
- data['H1GI6D']=data['H1GI6D'].replace(8, np.nan)
- data['H1GI6E']=data['H1GI6E'].replace(8, np.nan)
- data['BIO_SEX']=data['BIO_SEX'].replace(6, np.nan)
- data['NUMETHNIC']=(data['H1GI6A']+ data['H1GI6B'] + data['H1GI6C'] + data['H1GI6D']
- + data['H1GI6E'])
- data["AGE"]=data['IYEAR'] - data['H1GI1Y']
- #data["AGE"]=data["AGE"].replace(-1, np.nan)
- age=data['AGE'].value_counts()
- print(age)
- agedesc=data['AGE'].describe()
- print('\nStatistical Description of Age')
- print(agedesc)
- genderlabel={1:"Male", 2:'Female', 6:'unknown'}
- data['BIO_SEX']=data['BIO_SEX'].map(genderlabel).astype('category')
- gender = data['BIO_SEX'].value_counts()
- genderprc =data['BIO_SEX'].value_counts(normalize=True)
- print("\nCount of Gender")
- print(gender)
- print("\nPercent of each Gender")
- print(genderprc)
- def ethnic (row):
- if row["NUMETHNIC"] > 1:
- return 6
- if row['H1GI6A'] == 1:
- return 1
- if row['H1GI6B'] == 1:
- return 2
- if row['H1GI6C'] == 1:
- return 3
- if row['H1GI6D'] == 1:
- return 4
- if row['H1GI6E'] == 1:
- return 5
- else:
- return np.nan
- ethniclabels = {1:'White', 2:"Black", 3:'Native American', 4:"Asian", 5:'Other',
- 6:'Multiple'}
- data['ETHNICITY'] = data.apply(lambda row: ethnic (row), axis=1)
- data['ETHNICITY']=data['ETHNICITY'].map(ethniclabels)
- subwhite = data[(data['ETHNICITY'] == 'White')]
- whiteage = subwhite['AGE'].tolist()
- subblack = data[(data['ETHNICITY'] == 'Black')]
- blackage = subblack['AGE'].tolist()
- subnative = data[(data['ETHNICITY'] == 'Native American')]
- nativeage = subnative['AGE'].tolist()
- subasian = data[(data['ETHNICITY'] == 'Asian')]
- asianage = subasian['AGE'].tolist()
- subother = data[(data['ETHNICITY'] == 'Other')]
- otherage = subother['AGE'].tolist()
- submulti = data[(data['ETHNICITY'] == 'Multiple')]
- multiage = submulti['AGE'].tolist()
- ethnicities=[whiteage, blackage, nativeage, asianage, otherage, multiage]
- ethnicity = data['ETHNICITY'].value_counts()
- ethnicprc =data['ETHNICITY'].value_counts(normalize=True)
- print("\nCounts for Ethnic Groups")
- print(ethnicity)
- print("\nPercentage of each Ethnic Group")
- print(ethnicprc)
- #clean=data[['AGE', 'ETHNICITY', 'BIO_SEX']].dropna()
- plt.boxplot(ethnicities, labels = ('White', 'Black', 'Nat. Am.',
- 'Asian', 'Other', 'Multiple'))
- plt.xlabel("Ethnicity")
- plt.ylabel("Age")
- plt.title("Age Range of ADDHEALTH Respondents")
- plt.show()
The output (boxplot is shown above)
Ages (Count)
17 1169
16 1162
18 1149
15 1081
14 903
13 578
19 389
20 43
21 18
12 9
-1 3
Name: AGE, dtype: int64
Statistical Description of Age
count 6504.000000
mean 16.028905
std 1.810004
min -1.000000
25% 15.000000
50% 16.000000
75% 17.000000
max 21.000000
Name: AGE, dtype: float64
Count of Gender
Female 3356
Male 3147
Name: BIO_SEX, dtype: int64
Percent of each Gender
Female 0.51607
Male 0.48393
Name: BIO_SEX, dtype: float64
Counts for Ethnic Groups
White
4038
Black
1483
Other
362
Multiple
322
Asian
212
Native American
68
Name: ETHNICITY, dtype: int64


No comments:
Post a Comment