The name is absent



24


Stata Technical Bulletin


STB-20


. drop _all

. set obs 100

. gen x = invnorm(uniform())

. gen true.y = l+2*x

. save truth

Our program is

program define hetero
version 3.1
ɪf ∏-1-∏==∏7∏ {

global S_1 ,,a se_a b se.b,'
exit

>
use truth, clear
gen y = true.y + 2*(invnorm(uniform()) + 'lz*x)
regress y x

post -b [_cons] -se[.cons] _b[x] _se[x]
end

Note the use of ` 1 ' in our statement for generating y. ` 1 ' is an argument. If the argument’s value is 2, then the last part of
the statement is equivalent to “2*x”. We can run 10,000 simulations, setting the argument to 2 by typing

. simul hetero, args(2) reps(10000)

We might then analyze that data and try a different experiment, this time setting the argument to 1.5:

. simul hetero, args(1.5) reps(10000)

Our program hetero could, however, be more efficient because it rereads the file truth once every replication. It would
be better if we could read the data just once and, in fact, we can because we can use the query call to initialize ourselves. A
faster version reads:

program define hetero

version 3.1
ɪf ∏-ι-∏==∏7∏ {

use truth, clear                  (load the data just once)

global S_1 ,,a se_a b se.b,'
exit

>

gen y = true.y + 2*(invnorm(uniform()) + 'lz*x)
regress y x

post _b [_cons] -seE-Cons] _bEx] _seEx]

drop y                                          (because we will recreate it next time)

end

Assume we plan on replicating the experiment 10,000 times. In our original draft, we used the truth data once per replication,
meaning we performed 10,000 uses. The new version does this only once, saving 9,999 unnecessary uses.

Performance

simul is implemented in terms of post (see insert above) and it must, therefore, be slower. The good news is that it is
not much slower:

N          post (sec.) simul (sec.)

100             8.13            8.90

500           49.21          43.83

1000           89.19          87.16

These timings were performed on a 25MHz, DOS 486 computer.

Moreover, on the log-normal example, the direct post implementation took 13.5 minutes to perform 10,000 replications;
the simul solution took 14.5 minutes, for a total cost of 1 minute. post provides more flexibility than simul but, unless that
flexibility is necessary, simul provides a more convenient way to perform Monte Carlo simulations.



More intriguing information

1. Staying on the Dole
2. Qualification-Mismatch and Long-Term Unemployment in a Growth-Matching Model
3. PERFORMANCE PREMISES FOR HUMAN RESOURCES FROM PUBLIC HEALTH ORGANIZATIONS IN ROMANIA
4. Financial Markets and International Risk Sharing
5. On the Desirability of Taxing Charitable Contributions
6. The name is absent
7. THE EFFECT OF MARKETING COOPERATIVES ON COST-REDUCING PROCESS INNOVATION ACTIVITY
8. The name is absent
9. AN EXPLORATION OF THE NEED FOR AND COST OF SELECTED TRADE FACILITATION MEASURES IN ASIA AND THE PACIFIC IN THE CONTEXT OF THE WTO NEGOTIATIONS
10. Achieving the MDGs – A Note
11. Regional Intergration and Migration: An Economic Geography Model with Hetergenous Labour Force
12. Concerns for Equity and the Optimal Co-Payments for Publicly Provided Health Care
13. Informal Labour and Credit Markets: A Survey.
14. How much do Educational Outcomes Matter in OECD Countries?
15. Electricity output in Spain: Economic analysis of the activity after liberalization
16. TLRP: academic challenges for moral purposes
17. Knowledge, Innovation and Agglomeration - regionalized multiple indicators and evidence from Brazil
18. The name is absent
19. KNOWLEDGE EVOLUTION
20. The name is absent