Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

Re: st: Inconsistent Result of generating variables


From   Richard Williams <Richard.A.Williams.5@nd.edu>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: Inconsistent Result of generating variables
Date   Fri, 09 Apr 2004 21:22:02 -0500

At 09:22 PM 4/9/2004 -0400, Jitian Sheu wrote:
Hello, Thank you very much.
Based on your explaination, I try to use: (`b21')^2 instead of using
`b21'^2.
Stata creates the same results.
Here is how the original program can be rewritten using scalars rather than local macros (to me, this seems easier to read and write and is less error-prone):

clear
set obs 10
set seed 1204
gen x1=uniform()
gen emusq1=uniform()
gen emu1=uniform()
gen x2=x1^2
scalar b01=0.02
scalar b11=0.3
scalar b21=-0.25
gen tmptau1=emusq1+b01^2+(b11^2)*(x1^2)+(b21^2)*(x1^4)-2*b01*emu1-2* /*
*/ b11*emu1*x1-2*emu1*b21*x1^2+2*b01*b11*x1+2*b01*b21*x1^2+2*b11* b21*x1^3
gen tmptau1_alt=emusq1-2*emu1*(b01+b11*x1+b21*x2)+(b01+b11*x1+b21*x2 )^2
list tmptau1 tmptau1_alt
tab tmptau1
tab tmptau1_alt

The result of the list command is

. list tmptau1 tmptau1_alt

+---------------------+
| tmptau1 tmptau~t |
|---------------------|
1. | .8692592 .8692592 |
2. | .2181771 .2181771 |
3. | .2075188 .2075188 |
4. | .1309747 .1309747 |
5. | .6345458 .6345458 |
|---------------------|
6. | .4080512 .4080512 |
7. | .2966675 .2966675 |
8. | .3682937 .3682937 |
9. | .0604092 .0604092 |
10. | .9241688 .9241688 |
+---------------------+

*
* 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/




© Copyright 1996–2014 StataCorp LP   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index