Announcement

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

  • Using svy commands for egen and tables

    Hi all,
    I am using a DHS survey to calculate mean wages for age and income group (I asked another question about it in my previous post).
    I used svyset command at the beginning. However, I am not sure before which commands I am supposed to use svy command.
    Three major part of my calculations are:
    1. generating categorical variables for wages and level of education.
    2. Adding different income categories to generate monthly income.
    3. Two way table:
    table agecat edu_level, c(p50 adjincome n adjincome)

    Using svy command for table does not work and I am trying to figure out if this table is weighted. Also I am not sure for what commands I am supposed to used Svy.

    Any pointers would be helpful. Thank you.

  • #2
    Welcome to Statalist, Adhikari! To have a better chance of good answers, read the FAQ, especially #12 on how to ask good questions. That FAQ will ask that you show code (and results) that you've gotten so far and that you put them between CODE delimiters.

    All the statistics that table can display, with the exception of standard errors, rely only on the survey weights. So there's no need for svyset, just add the probability weight to the command.

    Below I show a one-way table, with price serving as the sampling weight. I show the three quartiles, as I consider the median insufficient to describe a population. Note that one can't use "n" as a statistic with weighted data, as table will show the total of all the weights, i.e. an estimate of N, the population size.

    Below the table analysis, I svyset the data with the same weight and "gear" as the PSU. I then show the results of Stas Kolenikov's epctile command (findit) with the svy option. epctile will estimate standard errors and confidence intervals for the percentiles.
    Code:
    capture log close
    set more off
    log using p01, replace text
    
    sysuse auto, clear
    gen one = 1  //to get count into table`
    table  foreign [pw =price],  contents( rawsum one p25 mpg p50 mpg p75 mpg)
    -------------------------------------------------------------
     Car type | rawsum(one)     p25(mpg)     med(mpg)     p75(mpg)
    ----------+---------------------------------------------------
     Domestic |          52           15           18           21
      Foreign |          22           18           23           25
    --------------------------------------------------------------
    svyset gear [pw = price]
    epctile mpg, percentiles(25 50 75) over(foreign) svy
    
    Percentile estimation
    ------------------------------------------------------------------------------
                 |             Linearized
             mpg |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
    -------------+----------------------------------------------------------------
    p25          |
               0 |         15        1.5    10.00   0.000     12.06005    17.93995
               1 |         18       2.25     8.00   0.000     13.59008    22.40992
    -------------+----------------------------------------------------------------
    p50          |
               0 |         18        1.5    12.00   0.000     15.06005    20.93995
               1 |         23       1.75    13.14   0.000     19.57006    26.42994
    -------------+----------------------------------------------------------------
    p75          |
               0 |         21       1.75    12.00   0.000     17.57006    24.42994
               1 |         25        4.5     5.56   0.000     16.18016    33.81984
    ------------------------------------------------------------------------------
    Last edited by Steve Samuels; 02 Nov 2017, 18:53.
    Steve Samuels
    Statistical Consulting
    [email protected]

    Stata 14.2

    Comment

    Working...
    X