2
$\begingroup$

Consider for example I have a retrospective data that contains one categorical variable Race and one other variable Weight

    Race         Weight
    White        0.0297
    White        0.9646
    White        0.1021

    Black        0.7185
    Black        0.8695
    Black        0.4661

    Other        0.1584
    Other        0.1311
    Other        0.3660  

My question is how do i produce a weighted dataset based on the weights above. I am aware of survey packages, wtd.table function etc but I like to know how these weights are applied for a categorical data above based a simple illustrative example . Thanks in advance.

$\endgroup$
1
$\begingroup$

A "weighted dataset" is simply one that contains a weight variable (like the one you've shown), and all the values in the dataset represent the observation itself and other observations (that are not included in the sample and hence aren't included in the dataset). So you don't typically produce a weighted dataset yourself: usually you obtain datasets that are already weighted from statistical agencies like The Bureau of Labor Statistics, Census, the Centers for Disease Control and Prevention, etc. For example, PRAMS is a large survey of maternity health with stratification and weighting. The survey website contains weighting documentation here for a specific state and year. Chances are, if you don't know what a weighted dataset is, you probably aren't going to be asked to produce one, so I'm going to assume you are asking how to use a weighted dataset.

What are weighted datasets?

Weighted datasets are frequently found in survey research because the respondents to a survey are sampled from a larger population of interest. The respondents to the sample represent themselves and others in their "weight class" who were not included in the sample. So the weights essentially inflate (or deflate) the value for each row in the dataset to represent the population.

How do I go about Using Weights for this dataset?

This is a difficult question to answer without knowing more about your particular data. Usually weighted datasets put out by large government agencies or research institutions include very specific instructions on how to weight your data during your analyses. It's important to find, read, and understand this documentation to properly carry out your analyses. Frequently the weights must be used in conjunction with design variables that also reside in the dataset that tell you how the data was sampled (e.g. multi-staged stratified, cluster sample with sampling carried out with probability proportional to size).

That being said, if you simply have weights in a dataset and no other documentation, and you can't find the documentation, then you might simply need to weight the categorical responses by simply adding up the weights in each category.

Example with your data

SAS

For example, let's analyze your weighted data using SAS's surveyfreq procedure (because it allows us to use weights). You would issue the following commands:

data work.temp;
input Race $ Weight;
cards;
White 0.0297
White 0.9646
White 0.1021
Black 0.7185
Black 0.8695
Black 0.4661
Other 0.1584
Other 0.1311
Other 0.3660
;
run;

proc surveyfreq data=work.temp;
tables Race;
weight Weight;
run;

This produces the table below as output:

enter image description here

You'll note that this table contains each race category, the weighted frequency (count), the standard deviation of the weighted frequency, the percent of people in the category, and the corresponding standard error. Keep in mind that the Percent" is a weighted percent. It is computed by taking the weighted frequency in each race class and dividing it by the sum of all the weights (the total Weighted Frequency cell of the table). So for example:

$\begin{eqnarray*} \%White & = & 1.0964/3.806*100\% & =& 28.80715\% \end{eqnarray*}$

R

In, R, you can use the following to obtain weighted frequencies:

> md<-read.table("D:\\weights.txt", header=T)
> wtd.table(md$race, weights = md$weight, normwt = FALSE)
 Black  Other  White 
2.0541 0.6555 1.0964 

The weighted frequencies match the weighted frequencies in SAS. Note, that in this simple case with categorical data, the weights are simply added up within each race category and the result represents the number of people of the given race in the population. To solidify this point. We can use the tapply function to add the weights in each race category, performing the same calculation as the wtd.table function:

> tapply(md$weight, md$race, sum)
Black  Other  White 
2.0541 0.6555 1.0964 
$\endgroup$
  • 1
    $\begingroup$ that is an excellent explanation. I got what I was looking for. Thanks $\endgroup$ – Sundown Brownbear May 28 at 21:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.