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

From |
"Martin Weiss" <martin.weiss1@gmx.de> |

To |
<statalist@hsphsun2.harvard.edu> |

Subject |
st: RE: Manipulation of the distribution |

Date |
Mon, 10 Nov 2008 13:29:48 +0100 |

Hard to figure out your email in my Outlook (weird formatting, of the code in particular). You want to look at -ssc d rnd- -h sample- the former because you run Stata9: Stata 10.1 now comes with built-in random number functionality. BTW, -ret list- is very much unnecessary in a loop. This command just serves to acquaint you with the return list, but is of no use in the loop... HTH Martin -----Original Message----- From: owner-statalist@hsphsun2.harvard.edu [mailto:owner-statalist@hsphsun2.harvard.edu] On Behalf Of linnrenee@hotmail.com Sent: Monday, November 10, 2008 1:11 PM To: statalist@hsphsun2.harvard.edu Subject: st: Manipulation of the distribution HiI have a dataset of hourly prices. Prices are identified by hour, weekday, week number, month and year. So within each day I have 24 hourly prices. What I'd like to do is to manipulate the prices by changing the distribution (changing the volatility of the prices following some assumptions on how the market will be changed). Let's say I want to increase the daily price volatility by for example increasing the standard deviation within each day. We've figured out a way to do this systematically using a group variable and directly changing the original standard deviation for each day. egen group_var=group(day week)capture drop new_no1gen new_no1=no1sum group_var forvalues i=1(1) `r(max)' { sum no1 if group_var==`i' ret list local org_mean `r(mean)' local org_sd `r(sd)' capture drop std_no1 gen std_no1=(no1-`org_mean')/`org_sd' if group_var==`i' sum std_no1 if group_var==`i' local new_mean `org_mean' local new_sd 1.2*`org_sd' replace new_no1=`new_sd'*std_no1 + `new! _mean' if group_var==`i' sum new_no1 if group_var==`i' }However, using this method will only systematically "stretch" the distribution so that the originally highest prices increases and the lowest prices decreases. Making the original distribution of prices more extreme.My trouble is to find a way to change the prices by randomly drawing a "price change" for each hourly price. I think what I need is to generate a variable for example one that is normally distributed with a given mean and standard deviation. Then I want to draw randomly from this distribution for each price in my dataset and add this element to the original price in order to have a "new price".Well, I have some trouble understanding how to actually generate new variables with a given distribution, say a normally or a binomial distributed variable (could really use som instruction on this). Second, I need to figure out how to tell Stata to draw randomly from this new variable distribution (one for each pri! ce observation) and then assigned the element drawn to the new price. (well this last thing would be easy as soon as I have the draws). I've looked into for example the rnd command written by Joe Hilbe, and also some other commands like normal, drawnormal ect (I'm running Stata 9), but I'm far from "fluent in Stata", so I could need some help.ThanksLinn _________________________________________________________________ Hold kontakten med Windows Live Messenger. http://clk.atdmt.com/GBL/go/msnnkdre0010000003gbl/direct/01/ * * 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/

**References**:**st: Manipulation of the distribution***From:*<linnrenee@hotmail.com>

- Prev by Date:
**Re: st: insheet delimiter problem** - Next by Date:
**Re: st: insheet delimiter problem** - Previous by thread:
**st: Manipulation of the distribution** - Index(es):

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