Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using the Collect system to collect values from a regression that uses survey weights

    Hello,

    I wanted to make a table using my data, which is comprised of 5 different cohorts, each with their own sampling weights. I can use the below code to create an excellent table:


    Code:
                  
    foreach cohortyear in 1992 1998 2004 2010 2016 {
        collect _r_b _r_ci, tag(model[`cohortyear']): logistic outcome_variable exposure_variable covriate_1 covariate_2 if cohort_year == `cohortyear'
    }
    
    collect layout ///
        (colname[_cons 0.exposure_variable 1.exposure_variable 0.covriate_1 1.covriate_1 0.covariate_2 1.covariate_2]#result) ///
        (model)

    However, I need to apply sampling weights to this regression. Each of the 5 cohorts have their own sampling weights (in other words I have variables samplingweight_1992 samplingweight_1998 samplingweight_2004 samplingweight_2010 and samplingweight_2016). I understand that I were not using the Collect system, I can just use the below code to run the regression using survey weights:

    Code:
    foreach cohortyear in 1992 1998 2004 2010 2016 {    
        svyset secu [pweight=samplingweight_`cohortyear'], singleunit(certainty) strata(stratum) vce(linearized)
        svy: logistic outcome_variable exposure_variable covriate_1 covariate_2 if cohort_year == `cohortyear'
    }

    However, I am unable to find a way to collect values from the svy/svyset commands with the Collect system. Is there an approach of collecting the _r_b and _r_ci from a "svy: logistic" regression, and make a Collect system table with them as shown above?



    Thank you so much in advance, and also my apologies for not providing a sample data_set and sample output. If you can recommend me a web dataset that has multiple cohort sampling weights (I am not sure which one is appropriate), I would be very happy to reword the question using that specific dataset!
    Last edited by Nathan Yu; 09 Oct 2024, 00:03.

  • #2
    Code:
    foreach cohortyear in 1992 1998 2004 2010 2016 {
        svyset secu [pweight=samplingweight_`cohortyear'], singleunit(certainty) strata(stratum) vce(linearized)
        collect _r_b _r_ci, tag(model[`cohortyear']): svy: logistic outcome_variable exposure_variable covriate_1 covariate_2 if cohort_year == `cohortyear'
    }
    collect layout ///
        (colname[_cons 0.exposure_variable 1.exposure_variable 0.covriate_1 1.covriate_1 0.covariate_2 1.covariate_2]#result) ///
        (model)
    ---------------------------------
    Maarten L. Buis
    University of Konstanz
    Department of history and sociology
    box 40
    78457 Konstanz
    Germany
    http://www.maartenbuis.nl
    ---------------------------------

    Comment


    • #3
      Thank you so much Maarten, I had made a mistake in attempting this earlier since it had resulted in an error. But it works perfectly now! Many thanks!

      Also, I have created a follow up question very much related to this question here (I think since it is a separate question, guidelines require it to be posted in a new forum post).


      Cheers.

      Comment


      • #4
        Dear Maarten,

        Thank you very much for your support earlier. I just wanted to follow up on this since my other post which had a similar question has not received suggestions. I wanted to ask if you can advise how to create a Table 1 (demographics table) that also has survey weights applied? The set up for this question is exactly as the opening post in the current thread.

        Normally I would use code such as below to obtain a Table 1:

        Code:
        collect: table ///
            (var) ///
            (cohortyear covariate_1), ///
                statistic(mean exposure_variable) ///
                    statistic(sd exposure_variable) ///
                statistic(fvpercent covariate_2) ///
                nototals
        
        collect recode result ///
            fvfrequency = variable_measure ///
            fvpercent = variable_spread ///
            mean = variable_measure ///
            sd = variable_spread
        
        collect label levels result variable_measure "Count / Mean" variable_spread "% / (SD)"
        
        collect layout ///
           (var[exposure_variable covariate_2]) ///
           (cohortyear#covariate_1#result[variable_measure variable_spread])
        However, this does not take survey weights into account. Do you know how would one make such a Table 1 using survey weights?

        My apologies that I am not providing sample data for this question, if you are aware of any public webuse dataset with multiple cohorts and each with their own survey weights, please let me know and I would be happy to reframe the question and repost!

        Comment

        Working...
        X