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

st: RE: RE: Gary King's Clarify for Stata - looping


From   "Alexander Severinsen" <alexande@nfh.uit.no>
To   <statalist@hsphsun2.harvard.edu>
Subject   st: RE: RE: Gary King's Clarify for Stata - looping
Date   Fri, 5 Nov 2004 00:59:01 +0100

Nick's ':
	twoway rspike plo12 phi12 ageaxis || rspike plo16 phi16 ageaxis
certainly gives more options than:
	graph7 plo12 phi12 plo16 phi16 ageaxis, s(iiii) c(||||)
Thanks a lot!

David, you are correct in your assumption. Your solution below tells
Stata how to do it, thanks very much!

Best wishes,
Alexander


-----Original Message-----
From: owner-statalist@hsphsun2.harvard.edu
[mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of David
Harrison
Sent: Thursday, November 04, 2004 10:57 AM
To: statalist@hsphsun2.harvard.edu
Subject: st: RE: Gary King's Clarify for Stata - looping


It seems to me that your main problem may be with floating point
precision.

When your price takes value -3.7021 this is stored in a float variable
as -3.072099924... and hence if you ask Stata to do something -if
price==-3.7021- it won't do it. You can get around this by storing
variables as doubles or by careful use of the -float()- command. See [U]
16.10 "Precision and problems therein" in the manuals for more details.
Brief example below...

David
david@icnarc.org

. set obs 1
obs was 0, now 1

. gen x=-3.0721

. count if x==-3.0721
    0

. di %20.18f x[1]
-3.0720999240875e+00

. count if x==float(-3.0721)
    1




-----Original Message-----
From: Alexander Severinsen [mailto:alexande@nfh.uit.no]
Sent: 04 November 2004 09:31
To: statalist
Subject: st: Gary King's Clarify for Stata - looping


Dear Statalister,

I am trying to use Clarify to construct confidence intervals for
predicted probabilities from a logit model. I have based my analysis on
the below code used in King, Tomz and Wittenberg's paper in American
Journal of Political Science: "Making the most of statistical analyses:
improving interpretation and presentation".

--- start code ----

version 6.0

estsimp logit turnout educate age agesqrd income white    /* run logit
*/
setx (income white) mean                          /* hold inc,wt at
means */
set more off                                      /* let output scroll
*/
generate plo12 = .                                /* lower bound if
ed=12 */
generate phi12 = .                                /* upper bound if
ed=12 */
generate plo16 = .                                /* lower bound if
ed=16 */
generate phi16 = .                                /* upper bound if
ed=16 */
generate ageaxis = _n+17 in 1/78                  /* contains
18,19,..,95 */
setx mean                                         /* set all vars to
mean */
local a = 18                                      /* begin with 18 ys
old */
while `a' <= 95 {                                 /* go to 95 years old
*/
   display "Simulating for age = `a'"             /* monitor our
progress */
   setx educate 12 age `a' agesqrd `a'^2*.01      /* set age, educ=12 ys
*/
   simqi, prval(1) genpr(edis12)		  /* save
Pr(Y=1|educ=12) */
   _pctile edis12, p(.5,99.5)			  /* fetch percentiles
*/
   replace plo12 = r(r1) if ageaxis==`a'	  /* save lo bound of ci
*/
   replace phi12 = r(r2) if ageaxis==`a'          /* save hi bound of ci
*/
   setx educate 16				  /* change educ to 16ys
*/
   simqi, prval(1) genpr(edis16)                  /* save
Pr(Y=1|educ=16) */
   _pctile edis16, p(.5,99.5)			  /* fetch percentiles
*/
   replace plo16 = r(r1) if ageaxis==`a'          /* save lo bound of ci
*/     
   replace phi16 = r(r2) if ageaxis==`a'	  /* save hi bound of ci
*/
   drop edis12 edis16			          /* clean-up our mess
*/
   local a = `a' + 1				  /* advance age 1 year
*/
}
sort ageaxis
set textsize 130
graph7 plo12 phi12 plo16 phi16 ageaxis, s(iiii) c(||||)   /*
   */ xlabel(18,24,30,36,42,48,54,60,66,72,78,84,90,95)  /*
   */ ylabel(.2,.4,.6,.8,1) l1(Probability of Voting)    /*
   */ gap(3) b2(Age of Respondent)

-------- end code -------

Now here King et al. uses a loop to go through all ages from 18 to 95,
and give CI for each year, in two different scenarios, saving the low
and hi of the CI in 4 different variables. Both the constructed ageaxis
and age are exactly similar. However, I am trying to plot predicted
probabilities for the difference in price between two products, together
with different scenarios of promotion. My price difference variables
consists of thousands of different prices, for example:

price
-3.7021
-3.7020
-2.6789
etc etc
until
2.7987

I have followed the approach above, but I count with:
	local a = `a' + 0.0001
This seems to work, Stata is counting until 2.7987, which is the last
price, but Stata does not save the CI's in new variables. I have worked
on this a couple of days, but I can't figure out why I can't get the
CI's saved in the new variables. I am using Stata 8.2. Any help on this
would be greatly appreciated. 

And while I'm at it being stuck, King et al. use:
	graph7 plo12 phi12 plo16 phi16 ageaxis, s(iiii) c(||||)
for plotting the CI's. It works under Stata7, but not under 8. Do I have
any better options available in Stata 8 to do this? Thanks.

Best wishes,
Alexander Severinsen


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



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

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