1 / 10

Labor Economics

Labor Economics. Exercise session # 1 Random data generation Jan Matuska November, 2006. Overview :. Graphing Generating random variables Generating random dummy variables from sample Drawing from multivariate distributions Throwing seeds

graham
Download Presentation

Labor Economics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Labor Economics Exercise session # 1 Random data generation Jan Matuska November, 2006

  2. Overview: • Graphing • Generating random variables • Generating random dummy variables from sample • Drawing from multivariate distributions • Throwing seeds • Loops and distribution of estimated coefficients

  3. Graphing • Histograms hist z2 ,den - histogram of variable z2 (density) hist z2 ,freq - histogram of variable z2 (frequency) dotplot z2 z3 - scatter plot graph of both variables kdensity z2 - produces kernel density estimates and graphs the result b) Sample cdf-s of variables: to generate variable cz3, the cdf values for z3 cumul z3 , gen(cz3) graph the sample cdf: line cz3 z3 , sort or: scatter cz3 z3 , sort

  4. Generating random variables 1 500 draws from the uniform distribution on [0,1] set obs 500 gen x1 = uniform() 500 draws from the standard normal distribution, mean 0, variance 1 gen x2 = invnorm(uniform()) 500 draws from the distribution N(1,2) gen x3 = 1 + 4*invnorm(uniform())

  5. Generating random variables 2 500 draws from the uniform distribution between 3 and 12 set obs 500 gen x4 = 3 + 9*uniform() compute 500 "z" values as 4-3*x4 + 8*x2 gen z = 4 - 3*x4 + 8*x2

  6. Generating random dummy variables from sample set obs 1000 create data for 1000 individuals gen smoke = uniform()>.7 assume that there is 70% chance that an individual smokes at time =1 smoke = 1 if the expression is true (uniform()>0.7) smoke = 0 if the expression is not true (uniform()<=0.7)

  7. Drawing from multivariate distributions clear mat m=(12,20,0) - matrix of means of RHS vars: y2, y3, error mat c=(5,-.6, 0 \ -.6,119,0 \ 0,0,.1) -covariance matrix of RHS vars drawnorm y2 y3 e , n(1000) means(m) cov(c) - draws a sample of 1000 observations from a normal distribution with specified means and covariances

  8. Throwing seeds allows you to generate a particular sample anytime again clear set obs 50 set seed 2 - seed number can be any positive integer STATA default is 123456789. gen z1 = invnorm(uniform()) set seed 2 gen z2 = invnorm(uniform()) set seed 4567803 gen z3 = invnorm(uniform()) dotplot z1 z2 z3 – we can see that z1 and z2 are identical and different from z3

  9. Loops and distribution of estimated coefficients Loop: while `i'<=500 { - i is the counter “commands” local i=`i'+1 } reg z x1 x2 – regress fits a model of dependent variable on other specified variables using linear regression The loop is used to acquire many estimated coefficients b1 which are different from the actual coefficient. The mean of all estimated coefficients should be the close approximation of the true coefficient we want to get

  10. Thank you forattention

More Related