Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Maarten Buis <maartenlbuis@gmail.com> |
To | statalist@hsphsun2.harvard.edu |
Subject | Re: st: Dummy variable for persistent values |
Date | Fri, 12 Jul 2013 11:00:42 +0200 |
On Thu, Jul 11, 2013 at 9:33 PM, Nicole Smit wrote: > For my bachelor thesis I am attempting to create a dummy variable as opennes > indicator when the trade/GDP ratio of a specific country in a particular year is higher than eg. 60%. I can do this by: gen opentGDP=0 > and then: replace opentGDP=1 if tradeGDP>=60 > > However, I would like to create a dummy for when the trade/GDP ratio is persistently higher than 60, so that actual openness of the country can be assumed instead of a random temporary increase in trade. Unfortunately I have not been able to find how I should do this. Here is an example: *------------------ begin example ------------------ // create some example data clear all set seed 123455 set obs 10 // ten countries gen country = _n gen openish = _n <=5 // first 5 countries are more likely to be open expand 10 // observe each country for 10 years bys country: gen year = _n+1999 gen trade = rbeta(10+20*openish,10) // to make it realistic: add a missing value replace trade = . in 17 // see what the example data looks like sort country year list, sepby(country) // answer the question gen byte miss = missing(trade) gen byte open = trade > .6 if miss == 0 bys country miss (year) : gen byte persistent_open = sum(open)==_N if miss==0 bys country miss (year) : replace persistent_open = persistent_open[_N] if miss == 0 // admire the result sort country year list, sepby(country) *------------------- end example ------------------- * (For more on examples I sent to the Statalist see: * http://www.maartenbuis.nl/example_faq ) Hope this helps, Maarten --------------------------------- Maarten L. Buis WZB Reichpietschufer 50 10785 Berlin Germany http://www.maartenbuis.nl --------------------------------- * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/