Hello Thomas,
just a few lines to suggest:
*********
egen groupvar = group(n pvalue)
local i 1
while `i' < 'maximum length of gaps' {
count if groupvar == .
if `r(N)' > 0 & `r(N) != . {
replace groupvar = groupvar[_n+1] if groupvar == .
}
local i = `i' + 1
}
count if groupvar == . /* should be 0 after the loop*/
*********
Now you have a grouping variable and moving the pvalues from one observation to another should not be too difficult.
Hope that helps,
Jochen
-------------------------------------------------------------------------------------------
Jochen Späth
Dipl.-Volkswirt
Institut für Angewandte Wirtschaftsforschung (IAW) Tübingen
Ob dem Himmelreich 1
72074 Tübingen
Tel.: +49-(0)7071-9896-14
Fax: +49-(0)7071-9896-99
EMail: [email protected]
IAW-Homepage: www.iaw.edu
-------------------------------------------------------------------------------------------
-----Ursprüngliche Nachricht-----
Von: [email protected] [mailto:[email protected]] Im Auftrag von Thomas Speidel
Gesendet: Mittwoch, 10. Dezember 2008 18:21
An: [email protected]
Betreff: st: Placing a non-missing value at beginning of a block
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.
--
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/
*
* 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/