Created
January 10, 2020 22:12
-
-
Save bbdaniels/4da8e7f88027f628bdf1739d26ddf038 to your computer and use it in GitHub Desktop.
Assignment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*Part I* | |
*** Setup | |
clear all //clear any open datasets | |
cls //clear the screen | |
version 15 | |
set more off | |
set linesize 255 | |
*** Generating a random varibale | |
set obs 100000 | |
set seed 1343758 | |
gen t=runiform(0,100) | |
replace t = round(t) | |
*** Summary statistics of theta | |
table t | |
codebook t | |
sum | |
des | |
*** Set up equations value | |
gen a = 100 | |
gen b = 2 | |
gen c = 150 | |
*** Set up equations for return on education | |
gen We = a + (b*t) | |
gen Wne = t | |
gen Cost_diff = (We - Wne)/c | |
gen thres = 1 + .0175 | |
*** Gets an education | |
sum Cost_diff if Cost_diff >= thres | |
*** Does not get an education | |
sum Cost_diff if Cost_diff < thres |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
clear all //clear any open datasets | |
*** Creating a uniform distribution 0 - 100 for N = 10 people | |
set obs 10 | |
set seed 188 | |
gen n10=runiform(0,100) | |
replace n10 = round(n10) | |
sum n10 | |
*** Store mean | |
return list | |
gen mn10 = r(mean) | |
sum mn10 | |
forvalues n10 = 1/1000 { | |
gen `n10' | |
replace `n10' = round(`n10') | |
sum `n10' | |
} | |
For Part 2, here is a similar loop to get you started:
cap mat drop results
forvalues obs = 1/5 {
forvalues iter = 1/1000 {
clear
set obs `=10^`obs''
gen val =
sum val
mat results = nullmat(results) ///
\ [`r(mean)',`=10^`obs'']
}
}
clear
svmat results
I'm sure there are errors in my code as I'm doing this on my phone and you will need to read documentation with functions you're not familiar with but this should be a basic framework for almost all simulations.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Check lines 29-30 in Part I. I don't think this is the right way to model the investment decision. Think about comparing the costs to the benefits using
>
.