Virata manual

svy: regress

Regression that respects the survey design.

What we have

  • weighted least squares with Taylor-linearised standard errors
  • the adjusted Wald F test that every slope is zero
  • checked against R's survey package

Coming later

  • svy: for the other models — svy: logit and the rest are refused

How you write it

svy: regress depvar [indepvars] [if]

Square brackets mean optional. A vertical bar means choose one.

What it does

svy: regress mpce age i.sector fits the same model as regress, but the coefficients are weighted and the standard errors are computed the way survey statisticians do (Taylor linearisation, also called the sandwich estimator). Confidence intervals use the design degrees of freedom.

The F test at the top is the adjusted Wald test that every slope is zero. Rows with a missing value leave the estimate but stay in the design, so the cluster structure is not damaged by a blank.

Watch out. Fitting an ordinary regress with weights is not the same thing. It gets the coefficients right and the standard errors wrong.

Try it

Every example below was run after sysuse vira.sample02, clear.

. svyset village [pw=multiplier], strata(stratum)
      pweight: multiplier
          VCE: linearized
  Single unit: missing
     Strata 1: stratum
 Sampling unit 1: village
        FPC 1: <zero>
The same thing in pandas and in R

pandas

design = dict(psu='village', strata='stratum', weight='multiplier')

R

library(survey)
design <- svydesign(ids = ~village, strata = ~stratum,
    weights = ~multiplier, data = df, nest = TRUE)

# This R was run in a real R (4.6.1) and gave the same numbers.
. svy: regress mpce age i.sector
Survey: Linear regression

Number of strata   =         12   Number of obs      =        6,000
Number of PSUs     =        400   Population size    =   10,612,910
                                  Design df          =          388
                                  F(   2,  387)      =       272.76
                                  Prob > F           =       0.0000
                                  R-squared          =       0.0887

------------------------------------------------------------------------------
             |             Linearized
        mpce | Coefficient  Std. err.      t   P>|t|     [95% conf. interval]
-------------+----------------------------------------------------------------
sector=Urban |    946.0186   41.52655   22.78   0.000     864.3734    1027.664
         age |    5.704484   1.030673    5.53   0.000     3.678081    7.730887
       _cons |    3125.311   50.91935   61.38   0.000     3025.199    3225.424
------------------------------------------------------------------------------
The same thing in pandas and in R

pandas

# survey regression: weighted least squares, Taylor-linearised covariance
# design: ['          VCE: linearized', '  Single unit: missing', '     Strata 1: stratum', ' Sampling unit 1: village', '        FPC 1: <zero>']

R

library(survey)
model <- svyglm(mpce ~ age + factor(sector), design = design)
summary(model)

# This R was run in a real R (4.6.1) and gave the same numbers.
The full built-in help (help svy: regress)
svy: regress depvar [indepvars] [if]

Linear regression that respects the survey design from svyset: the weights,
the strata and the primary sampling units.  Point estimates are weighted
least squares; the standard errors are Taylor-linearised (the "sandwich"),
and confidence intervals use the design degrees of freedom, PSUs minus strata.

    . svyset village [pw=multiplier], strata(stratum)
    . svy: regress mpce age i.sector

    Survey: Linear regression

    Number of strata   =         12   Number of obs      =        6,000
    Number of PSUs     =        400   Population size    =   10,612,910
                                      Design df          =          388
                                      F(   2,  387)      =       272.76
    ...

  * an `if` is a subpopulation: the rest of the sample stays in the design.
    Dropping those rows first would lose PSUs and shrink the standard errors
  * rows with a missing value leave the estimate but not the design
  * the weights come from svyset, so `[pw=...]` on this command is refused
  * with no regressors it estimates a constant, which is `svy: mean`
  * the F test is Stata's adjusted Wald test that every slope is zero

Not compared against a real Stata run yet: see docs/semantics.md.

Nearby

svyset svy: mean svy: total svy: proportion svy: ratio svy: tabulate