[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

From |
"Nick Cox" <n.j.cox@durham.ac.uk> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
st: RE: Generate new variable with an implicit formulation |

Date |
Wed, 8 Aug 2007 20:28:48 +0100 |

I have only very limited suggestions. 1. It may not matter here but in general I feel queasy when I see stuff like forval i = 0(0.001)1 { I would rather cycle over integers and manipulate further within the loop. When it ends up the same you lose nothing, but the other way round you can get bitten a bit more often. 2. Relative tolerances are usually more versatile than absolute ones, although I can't say whether this applies to your case. 3. It is largely cosmetic, but for a problem like this I prefer -inrange()-. if x - n*`i'^(n-1) + (n-1)*`i'^n < 0.0001 & x - n*`i'^(n-1) + (n-1)*`i'^n > -0.0001 then becomes if inrange(x - n*`i'^(n-1) + (n-1)*`i'^n, -0.0001, 0.0001) Alternatively, if abs(x - n*`i'^(n-1) + (n-1)*`i'^n) < 0.0001 4. If this were my problem, I might move it into Mata. Nick n.j.cox@durham.ac.uk Bob Hammond > I would like to define a new variable based on two current variables, > but the new variable cannot be expressed as an explicit > function of the > current variables. The relationship is: > > x = n*y^(n-1) - (n-1)*y^n > > where I have data on x and n and would like to create a new > variable, y. > x and y are restricted to the real numbers on the open interval (0,1) > and n is restricted to being a positive integer. Under these > restrictions, the function is well-behaved and provides a unique > solution, but not an explicit formulation. I can generate y with the > following loop: > > forvalues i=0(0.001)1 { > replace y=`i' if x - n*`i'^(n-1) + (n-1)*`i'^n < 0.0001 & x - > n*`i'^(n-1) + (n-1)*`i'^n > -0.0001 > } > > but I am wondering if there is a more efficient and precise > way. If this > type of loop is best, what precision would you recommend for > the steps > of `i’ and the tolerance (the ><0.0001)? (I’m on Intercooled > Stata 9 for > Windows if that matters.) Thanks in advance, * * 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/

**References**:**st: Generate new variable with an implicit formulation***From:*Bob Hammond <robert.g.hammond@vanderbilt.edu>

- Prev by Date:
**RE: st: RE: variance of R2** - Next by Date:
**Re: st: stcox output: p-value and CI don't agree** - Previous by thread:
**st: Generate new variable with an implicit formulation** - Next by thread:
**Re: st: Generate new variable with an implicit formulation** - Index(es):

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