如何使用survey_weight计算参与率?

问题描述 投票:0回答:1

我有一个包含调查回复的数据文件。这些受访者是我县的居民,他们被邀请参加当地的节日。变量是respondent_id、zip_code、survey_weight 和participated。参与是二进制的。 1 表示参加过节日,0 表示未参加。

我需要根据给定的survey_weight BY respondent_id 计算参与率。

我尝试了多种程序,包括调查手段和手段。

这就是我所做的。

proc surveymeans data=survey_data sum mean;
  strata zip_code;
  weight survey_weight;
  var participated;
  domain zip_code;
run;

还有这个。

proc means data=survey_data sum;
  class zip_code;
  var participated survey_weight;
  weight survey_weight;
  output out=zip_summary sum(participated)=total_part sum(survey_weight)=total_survey_weights;

跑;

data zip_summary;
  set zip_summary;
  participation_rate = total_part / total_survey_weights;
run;


proc print data=zip_summary;
  var zip participation_rate;
run;

虽然他们在跑,但我不知道这个数字是否正确。

sas survey
1个回答
0
投票

这听起来像是

PROC FREQ
程序的工作,但我在该设施方面不太强。另一种选择是使用
PROC SQL
来完成此操作。

PROC SQL;
    CREATE TABLE zip_summary AS
    SELECT 
        zip_code,
        survey_weight,

        MEAN(participated) AS participated FORMAT PERCENT20.2
    FROM
        survey_data
    GROUP BY
        zip_code,
        survey_weight
    ;
QUIT;

样本数据:

DATA survey_data;
    CALL STREAMINIT(1);
    DO zip_code = 900, 1000, 1200, 1300;
        DO survey_weight = 1 TO 2;
            DO respondent_id = 1 TO 1e3;
                participated = RAND("Bernoulli", 0.5);
                OUTPUT;
            END;
        END;
    END;
RUN;
/*
zip_code    weight     participated                           
-----------------------------------                           
     900         1           51.70%                            
     900         2           47.00%                            
    1000         1           49.30%                            
    1000         2           49.60%                            
    1200         1           51.10%                            
    1200         2           48.70%                            
    1300         1           50.70%                            
    1300         2           50.20%  
*/
© www.soinside.com 2019 - 2024. All rights reserved.