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

From |
Jeph Herrin <junk@spandrel.net> |

To |
statalist@hsphsun2.harvard.edu |

Subject |
Re: st: RE: How to use Postfile without using a new Stata dataset |

Date |
Thu, 04 Oct 2007 09:59:17 -0400 |

Thanks to Austin for patching up my hasty response. Jeph Herrin wrote:

I think your third approach is certainly not slower than using a -postfile-, but in any event this will be I think faster and cleaner than anything below: quietly { gene pvalue=. local number = r(N) forvalues i = 1/`number' { genhwi a[`i'] b[`i'] c[`i'] replace pvalue = r(p_exact) in `i' } } hth, Jeph tiago.pereira@incor.usp.br wrote:Thank you so much for your quick reply, Nick.Sorry, Nick, I will get there, sooner or later. I am still learning Stata.First off, your title is contradictory. The whole point of -postfile- is to create a new dataset.

Yes, I do need. Why?I don't have a clear sense of your aim, but it's not evident that you need alternatives to -postfile-.

My objetive is to use an approach that enables one to calculate some

statistics and report them in the current dataset.

For example, letīs assume that I have the following data set:

a b c study

26 85 41 1

12 56 23 2

45 85 96 3

45 86 91 4

My objetive is to obtain some statistic from -genhwi-, say, a P value of

the exact approach. My data set should look like this:

a b c study pvalue

26 85 41 1 0.056

12 56 23 2 0.862

45 85 96 3 0.996

45 86 91 4 0.005

However, one needs to type for each observation the number of counts of

each variable to run -genhwi- (and, of course, this is similar for several

other programs I need to run) and to fill the dataset manually. Currently,

since I am not fluent in Stata, I am aware of only three approaches to

obtain what I want:

First approach - Using postfile

-----------------BEGIN------------------------

postfile HWE pvalue using nickexample, replace

quietly summarize a

local number = r(N)

forvalues i = 1/`number' {

quietly summarize a if _n==`i'

local a = r(mean)

quietly summarize b if _n==`i'

local b = r(mean)

quietly summarize c if _n==`i'

local c = r(mean)

genhwi `a' `b' `c'

post HWE (r(p_exact))

}

postclose HWE

clear

use nickexample

describe

-----------------END---------------------------

Second approach - Using tempname

-----------------BEGIN------------------------

tempname M

quietly {

quietly summarize a

local number = r(N)

forvalues i = 1/`number' {

quietly summarize a if _n==`i'

local a = r(mean)

quietly summarize b if _n==`i'

local b = r(mean)

quietly summarize c if _n==`i'

local c = r(mean)

genhwi `a' `b' `c'

matrix `M' = nullmat(`M') \ (r(p_exact))

}

}

svmat double `M' , name(pvalue)

-----------------END---------------------------

Third approach - replacing observations

-----------------BEGIN------------------------

quietly {

gene pvalue=.

quietly summarize a

local number = r(N)

forvalues i = 1/`number' {

quietly summarize a if _n==`i'

local a = r(mean)

quietly summarize b if _n==`i'

local b = r(mean)

quietly summarize c if _n==`i'

local c = r(mean)

genhwi `a' `b' `c'

replace pvalue = r(p_exact) in `i'

}

}

-----------------END---------------------------

The first approach creates a new datased. Thatīs a problem for me. I do

not want that. The second alternative works only for up to 11,000

observations (I work with more than 100,000 observations) and, the third

one, although extremely straightforward in principle, is very

time-consuming.

Thx for any comment.

Tiago

*

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

**References**:**st: RE: How to use Postfile without using a new Stata dataset***From:*tiago.pereira@incor.usp.br

**Re: st: RE: How to use Postfile without using a new Stata dataset***From:*Jeph Herrin <junk@spandrel.net>

- Prev by Date:
**Repost: instrumental variables regression with random effects GLS using cross-section data and endogenous binary independent variable** - Next by Date:
**st: DHS ten years of data** - Previous by thread:
**Re: st: RE: How to use Postfile without using a new Stata dataset** - Next by thread:
**Re: st: RE: How to use Postfile without using a new Stata dataset** - Index(es):

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