Statalist The Stata Listserver


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

Re: st: question on distribution of values


From   Jeph Herrin <junk@spandrel.net>
To   statalist@hsphsun2.harvard.edu
Subject   Re: st: question on distribution of values
Date   Tue, 10 Oct 2006 14:35:33 -0400

Good point. I understood

> Also, if it helps, the order number is listed each
> time the zip code changes

to mean each -zip- occurred at most once per -order-
but this is fairly open to other interpretations.

Jeph


n j cox wrote:
This is a correct answer so long as each -zip-
occurs once and once only within groups defined
by -order-. That is true of the example but
I didn't understand it to be given in the problem.
For example, a given order might include two assignments
to the same ZIP.

If it were true, then you can get there without
-egen- by

bys order : gen newqt = qt / _N

Nick
n.j.cox@durham.ac.uk

Jeph Herrin

how about

bys order: egen newqt=mean(Qt/_N)

Andrea King

> Here's an example of the data I'm working with:
>
>
> Order# Qt Zip
> 1 5 00011
> 1 5 00012
> 1 5 00013
> 1 5 00014
> 2 3 00021
> 2 3 00023
> 3 8 00031
> 3 8 00035
> 3 8 00036
>
>
> Here are my problems:
>
> 1. The quantity of packages (qt) listed does not correspond directly to the zip code. For example, Order #1 requested 5 packages, to be distributed among each of four zip codes, or 1.25 packages per unique zip, not 5 packages per zip code.
>
> 2. I have yet to find the correct syntax that would allow me to create a variable that would show the distribution of Qt among the zip codes. I've played with egen, but can't get it to work.
>
> So my question is:
>
> how can I take one value of Qt (or if needed, an average of Qt), within each unique Order# and divide it by the number of unique zip codes by order#? Also, if it helps, the order number is listed each
> time the zip code changes, so a count of order# would probably work, too, but I'd prefer to do it by Zip.

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