Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Calculate percentage/frequency of a value in a survey object

I have a national survey composed of many variables, like this one (for the sake of semplicity I omitted some variables):

year  id  y.b   sex   income  married   pens   weight
2002  1   1950   F    100000     1       0      1.12
2002  2   1943   M    55000      1       1      0.55
2004  1   1950   F    88000      1       1      1.1
2004  2   1943   M    66000      1       1      0.6
2006  3   1966   M    12000      0       1      0.23
2008  3   1966   M    24000      0       1      0.23
2008  4   1972   F    33000      1       0      0.66
2010  4   1972   F    35000      1       0      0.67

Where id is the person interviewed, y.b is year of birth, married is a dummy (1 married, 0 single), pens is a dummy that takes value one if the person invest in a complementary pension form; weight are the survey weights.

Consider that the original survey is made up to 40k observations from 2002 to 2014(I filtered it in order to have only individuals that appear more than one time). I use this command to create a survey object:

d.s <- svydesign(ids=~1, data=df, weights=~weight)

Now that the df is weighted I want to find for example the percentage of women or the percentage of married person that invest in complementary pension; I read on R help and on the web to find a command to get the percentage but I didn't find the right one.

like image 1000
Laura R. Avatar asked Oct 06 '16 14:10

Laura R.


People also ask

How do you find percent frequency?

In this column, list the percentage of the frequency. To do this, divide the frequency by the total number of results and multiply by 100. In this case, the frequency of the first row is 1 and the total number of results is 10. The percentage would then be 10.0.

How do you calculate survey percentages?

It is calculated by dividing the total number of survey responses by the number of invitations sent to an audience (sample size). You then multiply that value by 100 for your response rate. For example, if you receive 380 responses from a sample of 1500, you would have a response rate of 25.33%.

What is frequency and percentage in research?

A percentage frequency distribution is a display of data that specifies the percentage of observations that exist for each data point or grouping of data points. It is a particularly useful method of expressing the relative frequency of survey responses and other data.


Video Answer


1 Answers

# same setup
library(survey)

df <- data.frame(sex = c('F', 'M', 'F', 'M', 'M', 'M', 'F', 'F'),
                married = c(1,1,1,1,0,0,1,1),
                pens = c(0, 1, 1, 1, 1, 1, 0, 0),
                weight = c(1.12, 0.55, 1.1, 0.6, 0.23, 0.23, 0.66, 0.67))

d.s <- svydesign(ids=~1, data=df, weights=~weight)

# subset to women only then calculate the share with a pension
svymean( ~ pens , subset( d.s , sex == 'F' ) )
like image 177
Anthony Damico Avatar answered Sep 24 '22 14:09

Anthony Damico