Announcement

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

  • Please help: translate R survey design code into Stata

    Dear all,
    Let me start by saying that I know very little to nothing of survey design, so this may be really simple, but I have no way of knowing.
    Someone shared with me a code to run a model. The code is in R, which I don't "speak", but for the most part I've been able to "translate" it into Stata to continue working with my dataset.
    However, there's a piece that has to do with survey design, where I am completely lost.

    The R code reads like this:

    # create a survey design object with SIPP design information
    z <-
    svrepdesign (
    data = y ,
    repweights = "repwgt[1-9]" ,
    type = "Fay" ,
    combined.weights = T ,
    rho =(1 - 1 / sqrt( 4 )) ,
    weights =~wpfinwgt
    )

    What would this look like in Stata?
    I was looking into svyset but wasn't finding all the options. Since it uses replicate weights, thought it would be BRR, but it also says Fay, so I'm very confused, to say the least.
    Anyone?

    Thanks in advance!

  • #2
    Indeed, I have never seen this code in R. This article presents parallel commands in Stata, SUDAAN and R. However, many of the specificities shown in #1 are lacking.
    Best regards,

    Marcos

    Comment


    • #3
      I am not familiar with the R code, either, but the Stata documentation (help svyset) says that Fay's adjustment is an option with BRR weights.
      David Radwin
      Senior Researcher, California Competes
      californiacompetes.org
      Pronouns: He/Him

      Comment


      • #4
        You may also check: a) the name of the package in R; b) then, get read its manual. If you're used to perform survey analysis, maybe this strategy would be helpful.

        By the way, this helpfile - svrepdesign - has interesting information, such as the use of rho as a shrinkage factor when selecting Fay's adjustment.
        Best regards,

        Marcos

        Comment


        • #5
          In the example below, I used Fay's adjustment and the same shrinkage factor you mentioned:

          Code:
          . */ get a data set
          
          . webuse stage5a
          
          . */ create a specific weight for Fay's adjustment
          
          . gen fayweight = pw*2
          
          . */ svyset - this example is multilevel, but it can be much simpler if you wish
          
          . svyset su1 [pweight=pw], strata(strata) fpc(fpc1) brrweight(fayweight) fay(0.5) vce(linearized) singleunit(missing) || su2, fpc(fpc2) || su3, fpc(fpc3) || su4, fpc(fpc4) || su5, fpc(fpc5) || _n, fpc(fpc6)
          
                pweight: pw
                    VCE: linearized
              brrweight: fayweight
                    fay: .5
            Single unit: missing
               Strata 1: strata
                   SU 1: su1
                  FPC 1: fpc1
               Strata 2: <one>
                   SU 2: su2
                  FPC 2: fpc2
               Strata 3: <one>
                   SU 3: su3
                  FPC 3: fpc3
               Strata 4: <one>
                   SU 4: su4
                  FPC 4: fpc4
               Strata 5: <one>
                   SU 5: su5
                  FPC 5: fpc5
               Strata 6: <one>
                   SU 6: <observations>
                  FPC 6: fpc6
          Best regards,

          Marcos

          Comment


          • #6
            By reading the R help file, I gather I can manage to - sorry for the pun - replicate your case.

            This is a mock example with a series of replicate weights.

            Your example shows 9 replicate weights but, for didatic purposes, I created just 3 (fake) weights.


            Code:
            . svyset, clear
            
            . gen fay1 = pw*2
            
            . gen fay2 = pw*3
            
            . gen fay3 = pw*3
            
            . svyset su1 [pweight=pw], strata(strata) fpc(fpc1) brrweight(fay1 fay2 fay3) fay(0.5) vce(linearized) singleunit(missing) || su2, fpc(fpc2) || su3, fpc(fpc3) || su4, fpc(fpc4) || su5, fpc(fpc5) || _n, fpc(fpc6)
            
                  pweight: pw
                      VCE: linearized
                brrweight: fay1 .. fay3
                      fay: .5
              Single unit: missing
                 Strata 1: strata
                     SU 1: su1
                    FPC 1: fpc1
                 Strata 2: <one>
                     SU 2: su2
                    FPC 2: fpc2
                 Strata 3: <one>
                     SU 3: su3
                    FPC 3: fpc3
                 Strata 4: <one>
                     SU 4: su4
                    FPC 4: fpc4
                 Strata 5: <one>
                     SU 5: su5
                    FPC 5: fpc5
                 Strata 6: <one>
                     SU 6: <observations>
                    FPC 6: fpc6
            
            .
            Edited:

            A much simpler command (indeed, I never used this way, but, apparently, we can do this when using rweights) would be something like:

            Code:
            svyset, clear
            svyset su1 [pweight=pw], brrweight(fay1 fay2 fay3) fay(0.5)
            Hopefully that helps.
            Last edited by Marcos Almeida; 29 Oct 2019, 14:46.
            Best regards,

            Marcos

            Comment


            • #7
              Thank you, Marcos. I think that might be just what I'm looking for!

              Comment

              Working...
              X