Statalist


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: st: Placing a non-missing value at beginning of a block


From   Thomas Speidel <[email protected]>
To   [email protected]
Subject   Re: st: Placing a non-missing value at beginning of a block
Date   Wed, 10 Dec 2008 11:57:36 -0700

Jeph, it is actually what I want: the n should not change, just the placement of the non-missing p-value.

Many thanks to all who contributed!

Quoting Jeph Herrin <[email protected]> Wed Dec 10 11:05:23 2008:


I'm a little confused because in the second set of data
below, the -pvalues- have moved but the -n-s have not, which
I think may not be what you want, but we'll do it anyway.

  gen group=_n
  sort n
  replace group=group[_n-1] if _n>1&!(mi(pvalue)&!mi(pvalue[_n-1]))

this creates a variable -group- which is constant for each of your
groups. Then, to shift the pvalue to the top of the group:

  bys group (n) : replace pvalue[1]=pvalue[_N]
  bys group (n) : replace pvalue[_N]=.

hth,
Jeph


Thomas Speidel wrote:
I am trying to create a spreadsheet ready table from within Stata and need to do some data management in order to go from this:

n    pvalue
1    .
2    .
3    .
4    .
5    0.151
6    .
7    .
8    .
9    .
10    0.000
11    .
12    .
13    .
14    .
15    0.146
16    .
17    .
18    .
19    .
20    .
21    0.001
...

To this:

n    pvalue
1    0.151
2    .
3    .
4    .
5    .
6    0.000
7    .
8    .
9    .
10    .
11    0.146
12    .
13    .
14    .
15    .
16    0.001
17    .
18    .
19    .
20    .
21    .
...

Notice that the blocks are not constant (some are 5, some are 6 etc. -this is just a portion of the data-). My difficulty lies in the fact that there is no natural grouping variable. I tried a mixture of subscripting and sequence generating commands, but did not get too far. The crucial part is that I need to place the non-missing pvalue at the beginning of the block, while right now it is at the end.

*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   http://www.stata.com/support/statalist/faq
*   http://www.ats.ucla.edu/stat/stata/




--
Thomas Speidel


*
*   For searches and help try:
*   http://www.stata.com/help.cgi?search
*   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