Book Image

Data Analysis with STATA

Book Image

Data Analysis with STATA

Overview of this book

Table of Contents (16 chapters)
Data Analysis with Stata
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Survey analysis in Stata code


Let's understand the Stata code to take a random sample from the survey data. A random sample is also called simple random sample (SRS):

use survey_data, clear
count
1095
set seed 2087620
sample 26
count
286

The following diagram represents the random sample generation mechanism:

Let's understand how to create pweights that are probability weights for the given sample.

Now, the sampling fraction in our case is given by the following:

So, the Stata code for pweight is as follows:

gen pweight = 1095/286

Similarly, FPC will be generated as follows:

gen fpc = 1095

This command generates the following output:

Now, we can leverage svyset, which is a command to give out the information stored in Stata with respect to the sampling design and plan. In this case, the PSU numbers remain the same, which means that Stata has a thorough understanding, which is similar to the understanding we have. As there is only one Stata, the sampling design is similar—in fact, it's the same as...