Aggregate data

5 pts.
Tags:
Database
Database programming
Can I manipulate aggregate tables at the census tract level? In essence, could I create dummy variables, such as: white, black, hipanic, other for 100 census tracts? Or is this only possible with individual level data?

Answer Wiki

Thanks. We'll let you know when a new response is added.

/* I will assume your Census_Table has a column called ‘Ethnicity’
with the following values Cauc, Caucasian, Afr_Amer, Pacific,
Asian, Hisp, Hispanic, Spanish, Amer_Indian
The values you want are White, Black, Hispanic, Other.
Execute the following function
*/
DELIMITER $$
CREATE FUNCTION Get_Race
(Ethnicity CHAR(15)) RETURNS CHAR(8)
BEGIN
DECLARE Race CHAR(8);
SET Race = ‘Other’;
SET Race = ‘White’ IF Ethnicity = ‘Cauc’ ELSE
SET Race = ‘White’ IF Ethnicity = ‘Caucasian’ ELSE
SET Race = ‘Black’ IF Ethnicity = ‘Afr_Amer’ ELSE
SET Race = ‘Black’ IF Ethnicity = ‘Negroid’ ELSE
SET Race = ‘Hispanic’ IF Ethnicity = ‘Hisp’ ELSE
SET Race = ‘Hispanic’ IF Ethnicity = ‘Hispanic’ ELSE
SET Race = ‘Hispanic’ IF Ethnicity = ‘Spanish’ ELSE
Return Race;
END $$
DELIMITER ;

/* Then — */
SELECT COUNT(*) Number_of, Get_Race(Ethnicity) Race
FROM Census_Table GROUP BY Race;
/* will yield you your desired results

/* I forgot the GROUP BY clause on my first submission

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following