Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
*case 1 population with intercept and estimation with intercept capture program drop testingb program define testingb, rclass drop _all set obs 200 * generating error term u drawn from normal distribution gen u = rnormal(0,2) * generating explanatory variable x randomly drawn from uniform distribution gen x = runiform() * get population estimator of b in model y = 1 + 2 * x + u gen y = 1 + 2 * x + u gen t = _n tsset t reg y x capture predict yhat, xb sum y global ymean = r(mean) sum x global xmean = r(mean) * calculate sample b, possible error from deviation operator gen double beta = [(yhat - $ymean)*(x - $xmean)]/ [(x - $xmean)*(x - $xmean)] sum beta return scalar m = r(mean) return scalar se = r(sd)/sqrt($obs) gen double e = y - yhat sum e return scalar em = r(mean) return scalar ese = r(sd)* r(sd) end global obs 200 * run the sub-program to get sample b for many times simulate m = r(m) se = r(se) em = r(em) ese = r(ese), reps(1000) : testingb list m sum m,detail sum em,detail sum ese, detail * the distribution of b is as betagraph: hist m, bin(100) normal name(betagraph, replace) hist em, bin(100) normal xline(0) name(errorgraph, replace) hist ese, bin(100) normal xline(4) name(evargraph, replace) graph combine errorgraph evargraph, /// title("Properties of Sample Error term Case 1") subtitle("Mean and variance") name(analyse1, replace) ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////// *case 2 population with intercept and estimation without intercept capture program drop testingb program define testingb, rclass drop _all set obs 200 * generating error term u drawn from normal distribution gen u = rnormal(0,2) * generating explanatory variable x randomly drawn from uniform distribution gen x = runiform() * get population estimator of b in model y = 1 + 2 * x + u gen y = 1 + 2 * x + u gen t = _n tsset t *intercept less regression reg y x, nocons capture predict yhat, xb sum y global ymean = r(mean) sum x global xmean = r(mean) * calculate sample b, possible error from deviation operator gen double beta = [(yhat - $ymean)*(x - $xmean)]/ [(x - $xmean)*(x - $xmean)] sum beta return scalar m = r(mean) /// return scalar se = r(sd)/sqrt($obs) gen double e = y - yhat sum e return scalar em = r(mean) return scalar ese = r(sd)* r(sd) end global obs 200 * run the sub-program to get sample b for many times simulate m = r(m) se = r(se) em = r(em) ese = r(ese), reps(1000) : testingb list m sum m, detail sum em, detail sum ese, detail * the distribution of b is as betagraph: hist m, bin(100) normal name(betagraph, replace) hist em, bin(100) normal xline(0) name(errorgraph, replace) hist ese, bin(100) normal xline(4) name(evargraph, replace) graph combine errorgraph evargraph, title("Properties of Sample Error term Case 1") subtitle("Mean and variance") name(analyse1, replace) ////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////// *case 3 population without intercept and estimation with intercept capture program drop testingb program define testingb, rclass drop _all set obs 200 * generating error term u drawn from normal distribution gen u = rnormal(0,2) * generating explanatory variable x randomly drawn from uniform distribution gen x = runiform() * get population estimator of b in model y = 2 * x + u gen y = 2 * x + u gen t = _n tsset t reg y x /// /// capture predict yhat, xb sum y global ymean = r(mean) sum x global xmean = r(mean) * calculate sample b, possible error from deviation operator gen double beta = [(yhat - $ymean)*(x - $xmean)]/ [(x - $xmean)*(x - $xmean)] sum beta return scalar m = r(mean) return scalar se = r(sd)/sqrt($obs) gen double e = y - yhat sum e return scalar em = r(mean) return scalar ese = r(sd)* r(sd) end global obs 200 * run the sub-program to get sample b for many times simulate m = r(m) se = r(se) em = r(em) ese = r(ese), reps(1000) : testingb list m sum m, detail sum em, detail sum ese, detail * the distribution of b is as betagraph: hist m, bin(100) normal name(betagraph, replace) hist em, bin(100) normal xline(0) name(errorgraph, replace) hist ese, bin(100) normal xline(4) name(evargraph, replace) graph combine errorgraph evargraph, /// title("Properties of Sample Error term Case 1") subtitle("Mean and variance") name(analyse1, replace) ///