Bookmark and Share

Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.


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

Re: st: RE: RE: Corrected Creating multiple observations from mixed observation?


From   Nick Cox <[email protected]>
To   [email protected]
Subject   Re: st: RE: RE: Corrected Creating multiple observations from mixed observation?
Date   Wed, 21 Sep 2011 14:44:01 +0100

I'd repeat my advice to bounce the data back to sender as a file
corrupted in one way is likely to be corrupted in other ways.

Otherwise, the following code shows some technique:

clear
input str30 Name double(Price1	Price2	Price3) 		
"Sedan 4D" 26290	1225	1750		
"Sedan 4D S Quattro Sedan 4D"	2918532665	14002250	22002750
end
gen islong = length(string(Price1, "%12.0f")) >= 10
expand 2 if islong
sort Name
gen work = ""
forval j = 1/3 {
	replace work = string(Price`j', "%25.0f")
by Name : gen price`j' = real(substr(work,1, length(work)/2)) if
islong & _n == 1
by Name : replace price`j' = real(substr(work,1 + length(work)/2,.))
if islong &  _n == 2
replace price`j' = Price`j' if !islong
}
drop work
l

I would call this kind of data management tricky even for very
experienced Stata users. Note that I have no idea how to fix doubled
up names as your example doesn't indicate to me how they should be
parsed.


On Wed, Sep 21, 2011 at 1:32 PM, Greenland, Andrew N
<[email protected]> wrote:
> Nick,
>
> This is roughly the pattern.  Occasionally the second line will read before the first, etc.
> Assuming I can identify which pattern goes where, How do I insert a new blank observation and fill it with the
> extracted info.
>
> Andrew
>
>
> ________________________________________
> From: [email protected] [[email protected]] On Behalf Of Nick Cox [[email protected]]
> Sent: Wednesday, September 21, 2011 2:41 AM
> To: [email protected]
> Subject: Re: st: RE: RE: Corrected Creating multiple observations from mixed observation?
>
> Your example implies that some lines of data are as wished and some
> are not. Also, your example seems to contradict your pattern. This
> might be fixable by some programming, or you might be better advised
> to go back to your source and indicate that the data structure is a
> mess.
>
> Nick
>
> On 21 Sep 2011, at 02:56, "Greenland, Andrew N" <[email protected]>
> wrote:
>
>> Yes,
>>
>> They're attached in a .txt file
>>
>> Thanks for the help!
>> ________________________________________
>> From: [email protected] [owner-
>> [email protected]] On Behalf Of Kieran McCaul
>> [[email protected]]
>> Sent: Tuesday, September 20, 2011 7:09 PM
>> To: [email protected]
>> Subject: st: RE: Corrected Creating multiple observations from mixed
>> observation?
>>
>> ...
>>
>> Can you provide a couple lines of real data?
>>
>>
>>
>> -----Original Message-----
>> From: [email protected]
>> [mailto:[email protected]] On Behalf Of Greenland,
>> Andrew N
>> Sent: Wednesday, 21 September 2011 6:04 AM
>> To: [email protected]
>> Subject: st: Corrected Creating multiple observations from mixed
>> observation?
>>
>> I need to insert a new observation into the dataset I am working on.
>> Multiple row's from a spreadsheet have been read into the same column
>> and I need to separate them and insert them into the dataset.
>>
>> The data should Look as follows:
>> var1        var2        var3
>> NAME1    Price1      Price2
>> NAME2    Price3      Price4
>>
>> Instead they look take on a pattern like this:
>> var1                        var2                     var3
>> NAME1NAME2                Price1Price3               Price2Price4
>>

*
*   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–2018 StataCorp LLC   |   Terms of use   |   Privacy   |   Contact us   |   Site index