If I understand your code correctly, it
can be condensed like this:
mdraws, dr(10) neq(1) prefix(h)
forvalues v=1/10 {
replace h1_`v'=(0.5)^0.5*h1_`v'
gen M`v'=2*(neworgmb-1)*(xb+h1_`v')
gen L`v'=ln(norm(M`v'))
}
Now, type
help egen
to find out about -egen, rowmean()-
Alternatively, you know about -forval-.
gen mean = 0
quietly {
forval v = 1/10 {
replace mean = mean + L`v'
}
replace mean = mean / 10
}
As you appear to want means across
observations, any panel structure is
irrelevant.
Your code and this code can be combined:
gen mean = 0
mdraws, dr(10) neq(1) prefix(h)
qui forvalues v=1/10 {
replace h1_`v'=(0.5)^0.5*h1_`v'
gen M`v'=2*(neworgmb-1)*(xb+h1_`v')
gen L`v'=ln(norm(M`v'))
replace mean = mean + L`v'
}
replace mean = mean/10
and there is scope for further simplification
if you don't want to use all the variables later.
Nick
[email protected]
[email protected]
> I am using the mdraws command and the following code to solve
> some integrals
> using monte carlo integration:
>
> mdraws, dr(10) neq(1) prefix(h)
> forvalues v=1/10 {
> replace h1_`v'=(0.5)^0.5*h1_`v'
> }
> forvalues v=1/10 {
> gen M`v'=2*(neworgmb-1)*(xb+h1_`v')
> }
> forvalues v=1/10 {
> gen L`v'=norm(M`v')
> }
> forvalues v=1/10 {
> replace L`v'=ln(norm(M`v'))
> }
>
> Here I end up with L1+...+ L10 and I want to compute the average
> (L1+...+L10)/10. In reality I have 1000 draws so it would be
> quite tedious
> if I had to write the whole expression down etc. I have panel
> data that are
> sorted by personal identification number and time. Any ideas
> how to proceed?
*
* For searches and help try:
* http://www.stata.com/support/faqs/res/findit.html
* http://www.stata.com/support/statalist/faq
* http://www.ats.ucla.edu/stat/stata/