Stata The Stata listserver
[Date Prev][Date Next][Thread Prev][Thread Next][Date index][Thread index]

st: RE: RE: Data manipulation question


From   "Nick Cox" <[email protected]>
To   <[email protected]>
Subject   st: RE: RE: Data manipulation question
Date   Thu, 29 Jul 2004 01:11:39 +0100

Here is another way to do it. 

su ccode , meanonly
local N = r(N) 
local newN = r(N) + r(max)  
set obs `newN' 
replace ccode = _n - `N' if mi(ccode) 
replace weight = 0 if mi(weight)
gsort ccode - weight 
drop if ccode == ccode[_n-1] 

Nick 
[email protected] 

> -----Original Message-----
> From: [email protected]
> [mailto:[email protected]]On Behalf Of Nick Cox
> Sent: 28 July 2004 23:25
> To: [email protected]
> Subject: st: RE: Data manipulation question
> 
> 
> This does the job, I think. I suspect there's 
> a neater way. 
> 
> su ccode, meanonly 
> set obs `r(max)'
> gen WEIGHT = 0 
> gen CCODE = _n 
> count if ccode < . 
> qui forval i = 1/`r(N)' { 
> 	replace WEIGHT = weight[`i'] in `=ccode[`i']'
> }
> 
> . l 
> 
>      +---------------------------------+
>      | ccode   weight   WEIGHT   CCODE |
>      |---------------------------------|
>   1. |     6      .33        0       1 |
>   2. |    10     .036        0       2 |
>   3. |    11     .005        0       3 |
>   4. |   181     .004        0       4 |
>   5. |   182        1        0       5 |
>      |---------------------------------|
>   6. |     .        .      .33       6 |
>   7. |     .        .        0       7 |
>   8. |     .        .        0       8 |
>   9. |     .        .        0       9 |
>  10. |     .        .     .036      10 |
>      |---------------------------------|
>  11. |     .        .     .005      11 |
>  12. |     .        .        0      12 |
>  13. |     .        .        0      13 |
>  14. |     .        .        0      14 |
>  15. |     .        .        0      15 |
>      |---------------------------------|
>  16. |     .        .        0      16 |
>  17. |     .        .        0      17 |
>  18. |     .        .        0      18 |
>  19. |     .        .        0      19 |
>  20. |     .        .        0      20 |
>      |---------------------------------|
>  21. |     .        .        0      21 |
>  22. |     .        .        0      22 |
>  23. |     .        .        0      23 |
>  24. |     .        .        0      24 |
>  25. |     .        .        0      25 |
>      |---------------------------------|
>  26. |     .        .        0      26 |
>  27. |     .        .        0      27 |
>  28. |     .        .        0      28 |
>  29. |     .        .        0      29 |
>  30. |     .        .        0      30 |
>      |---------------------------------|
>  31. |     .        .        0      31 |
>  32. |     .        .        0      32 |
>  33. |     .        .        0      33 |
>  34. |     .        .        0      34 |
>  35. |     .        .        0      35 |
>      |---------------------------------|
>  36. |     .        .        0      36 |
>  37. |     .        .        0      37 |
>  38. |     .        .        0      38 |
>  39. |     .        .        0      39 |
>  40. |     .        .        0      40 |
>      |---------------------------------|
>  41. |     .        .        0      41 |
>  42. |     .        .        0      42 |
>  43. |     .        .        0      43 |
>  44. |     .        .        0      44 |
>  45. |     .        .        0      45 |
>      |---------------------------------|
>  46. |     .        .        0      46 |
>  47. |     .        .        0      47 |
>  48. |     .        .        0      48 |
>  49. |     .        .        0      49 |
>  50. |     .        .        0      50 |
>      |---------------------------------|
>  51. |     .        .        0      51 |
>  52. |     .        .        0      52 |
>  53. |     .        .        0      53 |
>  54. |     .        .        0      54 |
>  55. |     .        .        0      55 |
>      |---------------------------------|
>  56. |     .        .        0      56 |
>  57. |     .        .        0      57 |
>  58. |     .        .        0      58 |
>  59. |     .        .        0      59 |
>  60. |     .        .        0      60 |
>      |---------------------------------|
>  61. |     .        .        0      61 |
>  62. |     .        .        0      62 |
>  63. |     .        .        0      63 |
>  64. |     .        .        0      64 |
>  65. |     .        .        0      65 |
>      |---------------------------------|
>  66. |     .        .        0      66 |
>  67. |     .        .        0      67 |
>  68. |     .        .        0      68 |
>  69. |     .        .        0      69 |
>  70. |     .        .        0      70 |
>      |---------------------------------|
>  71. |     .        .        0      71 |
>  72. |     .        .        0      72 |
>  73. |     .        .        0      73 |
>  74. |     .        .        0      74 |
>  75. |     .        .        0      75 |
>      |---------------------------------|
>  76. |     .        .        0      76 |
>  77. |     .        .        0      77 |
>  78. |     .        .        0      78 |
>  79. |     .        .        0      79 |
>  80. |     .        .        0      80 |
>      |---------------------------------|
>  81. |     .        .        0      81 |
>  82. |     .        .        0      82 |
>  83. |     .        .        0      83 |
>  84. |     .        .        0      84 |
>  85. |     .        .        0      85 |
>      |---------------------------------|
>  86. |     .        .        0      86 |
>  87. |     .        .        0      87 |
>  88. |     .        .        0      88 |
>  89. |     .        .        0      89 |
>  90. |     .        .        0      90 |
>      |---------------------------------|
>  91. |     .        .        0      91 |
>  92. |     .        .        0      92 |
>  93. |     .        .        0      93 |
>  94. |     .        .        0      94 |
>  95. |     .        .        0      95 |
>      |---------------------------------|
>  96. |     .        .        0      96 |
>  97. |     .        .        0      97 |
>  98. |     .        .        0      98 |
>  99. |     .        .        0      99 |
> 100. |     .        .        0     100 |
>      |---------------------------------|
> 101. |     .        .        0     101 |
> 102. |     .        .        0     102 |
> 103. |     .        .        0     103 |
> 104. |     .        .        0     104 |
> 105. |     .        .        0     105 |
>      |---------------------------------|
> 106. |     .        .        0     106 |
> 107. |     .        .        0     107 |
> 108. |     .        .        0     108 |
> 109. |     .        .        0     109 |
> 110. |     .        .        0     110 |
>      |---------------------------------|
> 111. |     .        .        0     111 |
> 112. |     .        .        0     112 |
> 113. |     .        .        0     113 |
> 114. |     .        .        0     114 |
> 115. |     .        .        0     115 |
>      |---------------------------------|
> 116. |     .        .        0     116 |
> 117. |     .        .        0     117 |
> 118. |     .        .        0     118 |
> 119. |     .        .        0     119 |
> 120. |     .        .        0     120 |
>      |---------------------------------|
> 121. |     .        .        0     121 |
> 122. |     .        .        0     122 |
> 123. |     .        .        0     123 |
> 124. |     .        .        0     124 |
> 125. |     .        .        0     125 |
>      |---------------------------------|
> 126. |     .        .        0     126 |
> 127. |     .        .        0     127 |
> 128. |     .        .        0     128 |
> 129. |     .        .        0     129 |
> 130. |     .        .        0     130 |
>      |---------------------------------|
> 131. |     .        .        0     131 |
> 132. |     .        .        0     132 |
> 133. |     .        .        0     133 |
> 134. |     .        .        0     134 |
> 135. |     .        .        0     135 |
>      |---------------------------------|
> 136. |     .        .        0     136 |
> 137. |     .        .        0     137 |
> 138. |     .        .        0     138 |
> 139. |     .        .        0     139 |
> 140. |     .        .        0     140 |
>      |---------------------------------|
> 141. |     .        .        0     141 |
> 142. |     .        .        0     142 |
> 143. |     .        .        0     143 |
> 144. |     .        .        0     144 |
> 145. |     .        .        0     145 |
>      |---------------------------------|
> 146. |     .        .        0     146 |
> 147. |     .        .        0     147 |
> 148. |     .        .        0     148 |
> 149. |     .        .        0     149 |
> 150. |     .        .        0     150 |
>      |---------------------------------|
> 151. |     .        .        0     151 |
> 152. |     .        .        0     152 |
> 153. |     .        .        0     153 |
> 154. |     .        .        0     154 |
> 155. |     .        .        0     155 |
>      |---------------------------------|
> 156. |     .        .        0     156 |
> 157. |     .        .        0     157 |
> 158. |     .        .        0     158 |
> 159. |     .        .        0     159 |
> 160. |     .        .        0     160 |
>      |---------------------------------|
> 161. |     .        .        0     161 |
> 162. |     .        .        0     162 |
> 163. |     .        .        0     163 |
> 164. |     .        .        0     164 |
> 165. |     .        .        0     165 |
>      |---------------------------------|
> 166. |     .        .        0     166 |
> 167. |     .        .        0     167 |
> 168. |     .        .        0     168 |
> 169. |     .        .        0     169 |
> 170. |     .        .        0     170 |
>      |---------------------------------|
> 171. |     .        .        0     171 |
> 172. |     .        .        0     172 |
> 173. |     .        .        0     173 |
> 174. |     .        .        0     174 |
> 175. |     .        .        0     175 |
>      |---------------------------------|
> 176. |     .        .        0     176 |
> 177. |     .        .        0     177 |
> 178. |     .        .        0     178 |
> 179. |     .        .        0     179 |
> 180. |     .        .        0     180 |
>      |---------------------------------|
> 181. |     .        .     .004     181 |
> 182. |     .        .        1     182 |
>      +---------------------------------+
> 
> .        log close
>        log:  c:\ado\personal\uk04grtalk\dubas.log
>   log type:  text
>  closed on:  28 Jul 2004, 23:22:23
> --------------------------------------------------------------
> ------------------
> Nick 
> [email protected] 
> 
> > -----Original Message-----
> > From: [email protected]
> > [mailto:[email protected]]On Behalf Of 
> > [email protected]
> > Sent: 28 July 2004 22:59
> > To: STATA list
> > Subject: st: Data manipulation question
> > 
> > 
> > Hello,
> > I have an excel file that looks something like this:
> > ccode   weight
> > 6               .33
> > 10            .036
> > 11            .005
> > 181           .004
> > 182           1
> > 
> > What I need to do is have ccode from 1 to 182, and weight to 
> > be 0(zero) if there
> > is not already a value in my excel file.  So, I hope to have 
> > something like
> > this in the end:
> > 
> > ccode   weight
> > 1          0.00
> > 2          0.00
> > etc.
> > 6          .33
> > 7          0.00
> > etc.
> > 182         1
> > 
> > Any suggestion?
> > Thanks,
> > Justin
> > 
> > 
> > *
> > *   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/



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