SHARE
TWEET

Untitled

a guest Apr 21st, 2019 58 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. * Example Stata script using postfile to create
  2. * a dataset of results from an analysis.
  3. * This example simulates a female wage penalty X times
  4. * and compares the density of estimates to the normal density.
  5.  
  6. * parameters for simulation
  7. local numiterations = 50
  8. local samplesize = 500
  9.  
  10. * set the simulation seed just for reproducibility of this artificial example
  11. set seed 6093358
  12.  
  13. * temporary names for postfile -- you can use permanent names if you want
  14. tempname memhold
  15. tempfile results
  16.  
  17. * initiate the post file:
  18. * this tells stata that the name memhold refers to the dataset results
  19. * this is also where you name variables in your dataset
  20. postfile `memhold' iteration b using "`results'"
  21.  
  22. * run the simulation
  23. forvalues i = 1/`numiterations' {
  24.   * generate some fake data
  25.   drop _all
  26.   set obs `samplesize'
  27.   * generate random female indicator
  28.   gen female = floor(2*runiform())
  29.   * generate random wage with female wage penalty
  30.   gen logwage = 3.1 - (0.20 * female) + rnormal(0,0.65)
  31.  
  32.   * do the analysis
  33.   reg logwage female
  34.   lincom female
  35.   local b = r(estimate)
  36.  
  37.   * post the results
  38.   post `memhold' (`i') (`b')
  39. }
  40.  
  41. * close post file, which creates the dataset results
  42. postclose `memhold'
  43.  
  44. * use results in some analysis
  45. use `results', clear
  46. lab var b "Estimated coefficient"
  47. kdensity b, normal
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top