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

Re: st: changing display format of macro contents


From   Nick Winter <[email protected]>
To   [email protected]
Subject   Re: st: changing display format of macro contents
Date   Tue, 18 Jan 2005 14:27:49 -0500

This will replace beta1hat with a reformatted version:

local beta1hat : di %3.2f `beta1hat'

In general, see -whelp extended_fcn-.

Or, using the `expansion_optr' ability (see -whelp macro-) you can do it in one step:

local beta1hat : di %3.2f `=coefs[1,1]'

Or, better yet, omit the beta1hat macro altogether:

lfit y x , ///
title("Fitted line: y = `: di %3.2f `=coef[1,2]'' + `: di 3.2f `=coef[1,1]'' * x")


--Nick Winter

At 11:08 AM 1/18/2005 -0800, you wrote:

i want to fit and draw a regression line and label the line, like this:

reg y x
matrix coefs=e(b)
loc beta1hat=coefs[1,1]
loc beta0hat=coefs[1,2]

lfit y x, title("fitted line: y = `beta0hat' + `beta1hat' * x")

when i do this, i get values for the estimated coefficients displayed
with far more precision than i want.  so i want to display only, say, 2
digits after the decimal for each macro.  i wasn't able to figure out a
way to apply a display format to a macro, so i tried adding this code
before the -lfit- command:

loc beta1hat = int(`beta1hat'*100+0.5)/100
loc beta0hat = int(`beta0hat'*100+0.5)/100

this works most of the time, but sometimes i get a graph that has a
title like this:

"y = 7.84000000001 + 2.31 * x"

or

"y = 7.83999999999 + 2.31 * x"

i assume that the problem is the rounding doesn't work in binary all the
time.  can anyone suggest a way around this?  (obviously if i were
making a single graph, i could put the coefficients in the title by
hand, but this code is part of a larger program, so i'd like it
automated.)

thanks,
sean.
_____________________________

please note new contact information:
_____________________________

sean f. reardon
associate professor of education and (by courtesy) sociology
school of education
485 lasuen mall, #315
stanford university
stanford, ca 94305-3096
650.736.8517 (office phone)
650.725.7412 (office fax)
[email protected]
_____________________________




*
*   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/
--------------------------------------------------------
Nicholas Winter 607.255.8819 t
Assistant Professor 607.255.4530 f
Department of Government [email protected] e
308 White Hall falcon.arts.cornell.edu/nw53 w
Cornell University
Ithaca, NY 14853-4601

*
* 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–2024 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   What's new   |   Site index