Statalist


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

RE: st: Replace string values


From   "sdm1" <[email protected]>
To   <[email protected]>
Subject   RE: st: Replace string values
Date   Wed, 12 Mar 2008 17:42:52 -0000

It's rather a coincidence but...how would you undertake the reverse
operation?  That is, I need to fill in the 'gaps' and go from:

>   +---------------------------+
>   |     table   quarter     n |
>   |---------------------------|
>   | qtr_a.dta         1   128 |
>   |                   2   129 |
>   |                   3   128 |
>   |                   4     4 |
>   | qtr_b.dta         1   130 |
>   |                   2   129 |
>   |                   3   130 |
>   |                   4     5 |
>   +---------------------------+

to 

>      qtr_a.dta         1   128
>      qtr_a.dta         2   129
>      qtr_a.dta         3   128
>      qtr_a.dta         4     4
>      qtr_b.dta         1   130
>      qtr_b.dta         2   129
>      qtr_b.dta         3   130
>      qtr_b.dta         4     5

Thanks.

Steve



-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Nick Cox
Sent: 12 March 2008 16:49
To: [email protected]
Subject: RE: st: Replace string values

I would clone the variable first. After all, you may want to reverse this
operation. 

Nick
[email protected] 

Ronnie Babigumira

Perfect.


Joseph Coveney wrote:
> Ronnie Babigumira wrote:
> 
> I am trying to produce a report using Stata's -list- command. The data
looks
> like this
> 
>          table   quarter     n
>      qtr_a.dta         1   128
>      qtr_a.dta         2   129
>      qtr_a.dta         3   128
>      qtr_a.dta         4     4
>      qtr_b.dta         1   130
>      qtr_b.dta         2   129
>      qtr_b.dta         3   130
>      qtr_b.dta         4     5
> 
> However, to make it easier on the readers eye (I think), I would list
it
> like this
> 
>          table   quarter     n
>      qtr_a.dta         1   128
>                        2   129
>                        3   128
>                        4     4
>      qtr_b.dta         1   130
>                        2   129
>                        3   130
>                        4     5
> 
> Any ideas how I can replace the non-first cases of each table with
missing
> 
> So far, I was trying to go down this path
> 
> bysort  table  quarter: replace  table = "" if table ! =  table[1]
> 
>
------------------------------------------------------------------------
--------
> 
> You were almost there.
> 
> Joseph Coveney
> 
> . clear *
> 
> . set more off
> 
> . input str20          table   byte quarter    int n
> 
>                     table   quarter         n
>   1.      qtr_a.dta         1   128
>   2.      qtr_a.dta         2   129
>   3.      qtr_a.dta         3   128
>   4.      qtr_a.dta         4     4
>   5.      qtr_b.dta         1   130
>   6.      qtr_b.dta         2   129
>   7.      qtr_b.dta         3   130
>   8.      qtr_b.dta         4     5
>   9. end
> 
> . bysort table (quarter): replace table = "" if _n > 1
> (6 real changes made)
> 
> . list, noobs sep(0)
> 
>   +---------------------------+
>   |     table   quarter     n |
>   |---------------------------|
>   | qtr_a.dta         1   128 |
>   |                   2   129 |
>   |                   3   128 |
>   |                   4     4 |
>   | qtr_b.dta         1   130 |
>   |                   2   129 |
>   |                   3   130 |
>   |                   4     5 |
>   +---------------------------+
> 
> . exit
> 
> end of do-file

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