Statalist


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

st: AW: programming, block-wise maxima


From   "Martin Weiss" <[email protected]>
To   <[email protected]>
Subject   st: AW: programming, block-wise maxima
Date   Mon, 13 Jul 2009 18:19:39 +0200

<> 

Full solution:

*************
clear*

input  panel_id 	entry    year     emp  out1
1476902     1998     1998     28    0     
1476902     1998     1999     7     0
1476902     1998     2000     0     0     
1476902     1998     2001     0     1     
1476902     1998     2002     0     0     
1476902     1998     2003     0     0     
1476902     1998     2004     0     2
1476902     1998     2005     15    0     
end

compress

bys panel_id (year): egen /* 
 */ out1_max=max((emp==0)*out1)

bys  panel_id (year): /* 
 */ replace  out1_max= . /* 
 */ if !(emp[_n-1]==0 & emp!=0)

list, noobs   
*************



HTH
Martin


-----Ursprüngliche Nachricht-----
Von: [email protected]
[mailto:[email protected]] Im Auftrag von Jochen Späth
Gesendet: Montag, 13. Juli 2009 18:07
An: [email protected]
Betreff: st: programming, block-wise maxima

Dear statalisters,

I'm stuck with a programming problem:

Suppose my data on business start-ups looks like this:

panel_id 	entry    year     emp  out1
1476902     1998     1998     28    0     
1476902     1998     1999     7     0
1476902     1998     2000     0     0     
1476902     1998     2001     0     1     
1476902     1998     2002     0     0     
1476902     1998     2003     0     0     
1476902     1998     2004     0     2
1476902     1998     2005     15    0     

What I would like to have is a variable, say out1_max, that contains the
maximum value of out1 - but STATA is meant to search for that maximum value
only inside periods during which emp == 0. Furthermore, out1_max should
contain all missings (besides the respective maximum values which should
appear in the year following the last observation with emp == 0). I.e., the
overall result should look as follows:

panel_id 	entry    year     emp  out1   out1_max
1476902     1998     1998     28    0       .
1476902     1998     1999     7     0       .
1476902     1998     2000     0     0       .
1476902     1998     2001     0     1       .
1476902     1998     2002     0     0       .
1476902     1998     2003     0     0       .
1476902     1998     2004     0     2       .
1476902     1998     2005     15    0       2

Any suggestions?

Thanks,
Jochen

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



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