{smcl} {* 29Jun2008}{...} {cmd:help wfegsample} {hline} {title:Title} {p2colset 5 12 24 2}{...} {p2col:{hi:Stata commands for selecting a sample}}{p_end} {title:List of examples} {p2col:1. Selecting a random sub-sample.}{p_end} {p2col:2. Training and confirmation samples.}{p_end} {p2col:3. Using an include file to load data and select a sample.}{p_end} {p2col:4. Create an indicator if a variable is missing.}{p_end} {p2col:5. Creating sample selection variables.}{p_end} {title:1. Keep if none of a set of variables are missing} mark notmissing // create variable to indicate if not missing markout notmissing var1 var2 ... varK // check these variables label def notmissing 0 0_missing 1 1_nomiss label val notmissing notmissing tab notmissing, missing {title:2. Selecting a random sub-sample} use wf-lfp, clear set seed 11020 generate isin = (uniform()>.8) label var isin "1 if in random sample (seed 11020)" label def isin 0 0_NoIn 1 1_InSample label val isin isin keep if isin tabulate isin, missing {title:3. Training and confirmation samples} use wf-articles, clear datasignature confirm set seed 1102 generate train1 = (uniform() < .5) label var train1 "Training sample?" label def trainlbl 0 "0Confirm" 1 "1Train" label val train1 trainlbl {title:4. Using an include file to load data and select a sample} // include: wf7-include-sample.doi // used by: wf7-include-sample.do // task: define sample for tenure example // project: workflow chapter 7 // author: scott long \ 2008-04-09 // #1 // load data and select sample use wf-tenure, clear datasignature confirm drop if year>=11 // drop cases with long time in rank drop if prestige<1 // drop if unrated department {title:5. Create an indicator if a variable is missing} // indicator of whether a case has missing data for art generate Mart = missing(art) label var Mart "Is art missing?" label def Lismiss 0 0_valid 1 1_missing label val Mart Lismiss {title:6. Creating sample selection variables} generate sampfem = (female==1) label var sampfem "Sample: females only" generate sampmale = (female==0) label var sampmale "Sample: males only" label def Lsamp 0 0_Drop 1 1_InSample label val sampfem Lsamp label val sampmale Lsamp {p2colset 5 12 12 2} {title:Also see} {helpb wf} INCLUDE help wf_footer