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: AW: Forvalues [was cut function]
From
Katia Bobulova <[email protected]>
To
[email protected]
Subject
Re: st: AW: Forvalues [was cut function]
Date
Thu, 5 Aug 2010 16:42:49 +0100
Dear Martin,
thank you very much for your help. Your ad-hoc-ish solution works very well.
I have another problem when I consider also the price.Maybe you can
help me also for this.
This are my data:
Date Time Price Newtime Quantity
03jan2000 . . 93000 0
03jan2000 93157 148.25 93100 1
03jan2000 93201 148.25 93200 1
03jan2000 93208 148.25 93200 1
03jan2000 93211 148.63 93200 1
03jan2000 93248 148.25 93200 1
03jan2000 93252 148.25 93200 1
03jan2000 93301 148.46 93300 1
Now I want to aggregate the quantity for the newtime, date and price.
Is there a way to keep the chronological order, i.e. the new quantity
at price 148.25 for the newtime 93200 must not be a single quantity of
4 but two quantity of two, which preserve the chronological order. In
other words, I would like to have a result like this:
Date Time Price Newtime Quantity NewQuantity
03jan2000 . . 93000 0 0
03jan2000 93157 148.25 93100 1 1
03jan2000 93201 148.25 93200 1 2
03jan2000 93208 148.25 93200 1 2
03jan2000 93211 148.63 93200 1 1
03jan2000 93248 148.25 93200 1 2
03jan2000 93252 148.25 93200 1 2
03jan2000 93301 148.46 93300 1 1
And then I can drop the duplicate.
I tried with collapse, constructing an id, but I cannot reach this result.
Could you please help me?
Thank you very much.
Katia
2010/8/3 Dr. Martin Weiss <[email protected]>:
>
> <>
>
> This solution is very ad-hoc-ish:
>
>
> *************
> clear*
>
> inp str10 Data Time
> 03jan2000 93157
> 03jan2000 93201
> 03jan2000 93248
> 03jan2000 93305
> 03jan2000 93602
> 03jan2000 93805
> 03jan2000 94000
> end
>
> compress
>
> gen date=date(Data, "DMY")
> form date %td
>
> drop Data
>
> replace Time=floor(Time/100)*100
> list, noo
>
> su Time, mean
> local min=r(min)
> local max=r(max)
> save myfile, replace
>
> //generate dataset featuring possible "Time" values
> drop _all
> set obs `=(round(`max', 1000)-round(`min', 1000))/100+1'
>
> gen Time=round(`min', 1000)+(_n-1)*100
> joinby using myfile, unmatched(both)
> drop _merge
> so date
> replace date=date[1]
> so Time
> li, noo
> *************
>
>
>
> HTH
> Martin
>
> -----Ursprüngliche Nachricht-----
> Von: [email protected] [mailto:[email protected]] Im Auftrag von Katia Bobulova
> Gesendet: Dienstag, 3. August 2010 17:27
> An: [email protected]
> Betreff: st: Forvalues [was cut function]
>
> Dear all,
>
> I am still trying to solve my problem to have equal time intervals for
> each data.
>
> This is what I have:
>
> Data Time
> 03jan2000 93157
> 03jan2000 93201
> 03jan2000 93248
> 03jan2000 93305
> 03jan2000 93602
> 03jan2000 93805
> 03jan2000 94000
>
> And this is what I want to obtain:
>
> Data Time
> 03jan2000 93000
> 03jan2000 93100
> 03jan2000 93200
> 03jan2000 93200
> 03jan2000 93300
> 03jan2000 93400
> 03jan2000 93500
> 03jan2000 93600
> 03jan2000 93700
> 03jan2000 93800
> 03jan2000 93900
> 03jan2000 94000
>
> I thought that a possibler solution would be to construct a variable
> with all the time intervals for each data.
>
> I tried to give Stata this command:
>
> forval data: 03jan2000/24feb2000{
> gen time2=93000 (1) 94000
> }
>
> The command doesn't work.
>
> Do you know if this could a possible solution to my problem and if
> yes, how to write the right code?
>
> Thank you very much.
>
> Katia
> *
> * 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/
>
*
* 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/