tag:blogger.com,1999:blog-5290984163937382875.post417234010002329473..comments2017-10-17T09:22:18.092+03:00Comments on The Stata Project-Oriented Guide: Step #6: Automation - Separating the Men from the Boysstatamanhttp://www.blogger.com/profile/13749462261829425392noreply@blogger.comBlogger27125tag:blogger.com,1999:blog-5290984163937382875.post-30354624277789111322016-02-23T10:45:16.685+02:002016-02-23T10:45:16.685+02:00This comment has been removed by the author.e3clearyhttps://www.blogger.com/profile/07135848066178338743noreply@blogger.comtag:blogger.com,1999:blog-5290984163937382875.post-56322144927023872622014-08-27T17:42:40.370+03:002014-08-27T17:42:40.370+03:00Dear Stataman,
Thank you so much for your tutoria...Dear Stataman, <br />Thank you so much for your tutorial.However I tried to apply some of the Stata codes in your blog for my analysis, but it didn't work. <br /><br />My dataset contains a set of 4 dependent variables which were cost1, cost2, cost3, cost4, and a set of 4 explanatory variables such as country, company, market, province. My aim is to run regression models to find out the significant explanatory variables. Basically I want the full model and the reduced models for each of the costs which were as followings:<br /><br />Cost 1 <- a + b1country + b2company + b3market + b4province<br />Cost 1<-a + b1country + b2company + b3market <br />Cost 1<- a + b1 country + b2company<br />Cost1<-a+b1country<br /><br />Cost 2 <- a + b1country + b2company + b3market + b4province<br />Cost 2<-a + b1country + b2company + b3market <br />Cost 2<- a + b1 country + b2company<br />Cost2<-a+b1country <br /><br />and so on.....to Cost n <br /><br />Would you please help me with the loops code as it would take ages to run each regression individually?<br /><br />Thank you so much! FongTran Phuonghttps://www.blogger.com/profile/08051545852317227116noreply@blogger.comtag:blogger.com,1999:blog-5290984163937382875.post-30553365836620058682014-02-22T20:18:14.805+02:002014-02-22T20:18:14.805+02:00very good information and Inspiring & Interest...very good information and Inspiring & Interesting.<br /><br />success always<br />http://tokoobatbiusasli.blogspot.comaneka obathttps://www.blogger.com/profile/16064339766200853342noreply@blogger.comtag:blogger.com,1999:blog-5290984163937382875.post-87376338667326396782013-05-30T03:10:06.494+03:002013-05-30T03:10:06.494+03:00Thank you very much for all of your advises!! They...Thank you very much for all of your advises!! They have been really helpful to my work! I just wanted to make one remark in the kindest way possible: I believe that the title of the post is quite sexist. Like, if only 'men' use this kind of commands, which is the kind that use 'women' or 'girls'? Why don't you title it: separating adults' commands from children's! That would be totally gender-neutral! Regards!Unknownhttps://www.blogger.com/profile/05510127384644056385noreply@blogger.comtag:blogger.com,1999:blog-5290984163937382875.post-15008013627441764312013-03-07T12:15:14.385+02:002013-03-07T12:15:14.385+02:00This is very uncommon, though, and makes the code ...This is very uncommon, though, and makes the code less readable.<br /><a href="http://www.southfloridavendingmachines.com/" rel="nofollow">South Florida Vending Machines Services</a>South Florida Vending Machines Serviceshttps://www.blogger.com/profile/09002328086845632091noreply@blogger.comtag:blogger.com,1999:blog-5290984163937382875.post-54329728424860394412012-06-11T13:27:33.542+03:002012-06-11T13:27:33.542+03:00Hey Stataman,
This tutorial has been very useful,...Hey Stataman,<br /><br />This tutorial has been very useful, thank you so much for sharing.<br /><br />I have a quesiton, My data set is panel data on daily basis. I would like to run daily regression for each quarter and extract the estimates to have a quarterly time series of estimates (coef, tstat, rsquare and stand error). but my problem is Not all my dependent var or id available in all quarters, some of them are present at the beginning of sample and some only at the end.<br /><br />when I run my loop to run the regression it gives me the following error message:<br /><br />no observations found or no variable defined.<br /><br />how can I solve this problem?<br /><br />Best, <br /><br />Mahmoudmahmoud aymohttps://www.blogger.com/profile/10986889959304870935noreply@blogger.comtag:blogger.com,1999:blog-5290984163937382875.post-78351384341154578862011-10-27T06:50:28.229+02:002011-10-27T06:50:28.229+02:00HELP needed
My data is the exicison of skin cancer...HELP needed<br />My data is the exicison of skin cancers from patients over 4 1/2 year period. Many people have multiple events (max is 120) and I want to count number of lesions if the cancers are <=90days apart. If they are then I want to also delete that record. I have started working through the permutations but if anyone can suggest how i can loop this?<br />doservice = date lesion taken out<br />numsyn1 = number of skin lesions taken out on that day.<br />For example if person had 2 events, I would look at difference between 1-2<br />if person had 3 events, I would first look at 1-3, then 1-2 then 2-3. <br />if person had 4 events, I would look at 1-4, then 1-3, then 1-2 then 2-4, then 2-3 then 3-4<br /> <br />(starting to get combinations formation occuring)<br /> <br />Please see below.<br />//1-4 bysort id (event) : replace numsyn1 = numsyn1 + numsyn1[_n+3] if (doservice[_n+3] - doservice[1]<=90) drop if event==4 & (doservice - doservice[_n-3]<=90)//for 3 events<br />//1-3 bysort id (event) : replace numsyn1 = numsyn1 + numsyn1[_n+2] if (doservice[_n+2] - doservice[1]<=90) drop if event==3 & (doservice - doservice[_n-2]<=90)//for 2 events<br />//1-2 bysort id (event) : replace numsyn1 = numsyn1 + numsyn1[_n+1] if (doservice[_n+1] - doservice[1]<=90) drop if event==2 & (doservice - doservice[_n-1]<=90)<br />//SECOND LOOP///for 4 events<br />//2-4 bysort id (event) : replace numsyn1 = numsyn1 + numsyn1[_n+2] if event==2 & (doservice[_n+2] - doservice<=90) drop if event==4 & (doservice - doservice[_n-2]<=90)<br />//for 3 events<br />//2-3 bysort id (event) : replace numsyn1 = numsyn1 + numsyn1[_n+1] if event==2 & (doservice[_n+1] - doservice<=90) drop if event==3 & (doservice - doservice[_n-1]<=90)<br /> <br />//THIRD LOOP///for 4 events<br />//3-4 bysort id (event) : replace numsyn1 = numsyn1 + numsyn1[_n+1] if event==3 & (doservice[_n+1] - doservice[1]<=90) drop if event==4 & (doservice - doservice[_n-1]<=90)<br /> id doservice survday failure numsyn1 event repeat newstopdate maxevent <br />9 20-Feb-08 41 1 1 1 1 30-Jun-08 2 <br />9 1-Apr-08 90 0 1 2 0 30-Jun-08 2 <br />14 1-Jun-04 14 1 1 1 1 30-Jun-08 2 <br />14 15-Jun-04 1476 0 1 2 0 30-Jun-08 2 <br />15 6-Jun-06 268 1 1 1 0 1-Mar-07 3 <br />15 1-Mar-07 257 1 1 2 0 13-Nov-07 3 <br />15 13-Nov-07 230 0 1 3 0 30-Jun-08 3 <br />16 20-Jan-04 497 1 1 1 0 31-May-05 4 <br />16 31-May-05 7 1 1 2 1 16-Jun-05 4 <br />16 7-Jun-05 9 1 1 3 1 30-Jun-08 4 <br />16 16-Jun-05 1110 0 1 4 0 30-Jun-08 4 <br /><br />Regards<br />NiyatiNiyati Sharmahttps://www.blogger.com/profile/15115913872918864493noreply@blogger.comtag:blogger.com,1999:blog-5290984163937382875.post-62830551153456313802011-03-17T21:44:34.080+02:002011-03-17T21:44:34.080+02:00hi,
blog very useful for someone like me (scared ...hi,<br /><br />blog very useful for someone like me (scared of stata and just want to get done with it soon...)<br /><br />q: i need to create an indicator variable such that there are ten 1s only (out of 19 observations). this is going to be part of a loop, where i'll need stata to come up with different combinations of 1 and 0 distributions... and i'll need it to do other stuff with this variable... but i'll get my doubts clarified one at a time...<br /><br />thanks<br />sheetalsheetalhttps://www.blogger.com/profile/13026148659740730086noreply@blogger.comtag:blogger.com,1999:blog-5290984163937382875.post-11481359005223198572011-03-04T00:26:02.245+02:002011-03-04T00:26:02.245+02:00Thank you, very helpful!Thank you, very helpful!rec.bicyclehttps://www.blogger.com/profile/08343355365992892780noreply@blogger.comtag:blogger.com,1999:blog-5290984163937382875.post-33031941148038979702010-06-23T09:19:32.051+03:002010-06-23T09:19:32.051+03:00Thank you very much!Thank you very much!Longhttps://www.blogger.com/profile/13265830019277964567noreply@blogger.comtag:blogger.com,1999:blog-5290984163937382875.post-74124833328743521662010-06-22T19:54:48.202+03:002010-06-22T19:54:48.202+03:00Hi,
You may find additional automation tips and t...Hi,<br /><br />You may find additional automation tips and tricks in my personal webpage, for a short course that I co-taught. Look for the third lecture notes file of Stata:<br /><br />http://www.stanford.edu/~roymill/cgi-bin/computing/material.phpstatamanhttps://www.blogger.com/profile/13749462261829425392noreply@blogger.comtag:blogger.com,1999:blog-5290984163937382875.post-11078547824467203392010-06-22T05:19:17.097+03:002010-06-22T05:19:17.097+03:00Hi Stataman,
Could you please guide me how to exp...Hi Stataman,<br /><br />Could you please guide me how to export the results from Stata into Excel file format.<br /><br />For example, after I run the "summarize" command and I want to save the result into a Excel file. Please help !!!!!!!!!!!!!!!!!!Longhttps://www.blogger.com/profile/13265830019277964567noreply@blogger.comtag:blogger.com,1999:blog-5290984163937382875.post-20080117744764297732010-06-07T05:16:16.122+03:002010-06-07T05:16:16.122+03:00Thank you very muchThank you very muchLonghttps://www.blogger.com/profile/13265830019277964567noreply@blogger.comtag:blogger.com,1999:blog-5290984163937382875.post-47926450964873622682010-06-07T04:09:26.810+03:002010-06-07T04:09:26.810+03:00Hi,
You are not using the back-tick for your loca...Hi,<br /><br />You are not using the back-tick for your local when you call it, you are using the regular tick. The back-tick on my keyboard is in the top-left corner of the main set of keys (left to the 1 key).<br />do:<br />di `rsqv'<br />and not:<br />di 'rsgv'statamanhttps://www.blogger.com/profile/13749462261829425392noreply@blogger.comtag:blogger.com,1999:blog-5290984163937382875.post-48297340299568998822010-06-07T03:49:19.293+03:002010-06-07T03:49:19.293+03:00Hi Stataman
I have problem with local command. I ...Hi Stataman<br /><br />I have problem with local command. I use Stata 11/MP.<br />I have a dofile like this:<br />sysuse auto, clear<br />regress mpg weight<br />local rsqf e(r2)<br />local rsqv = e(r2)<br />di 'rsqf' // this has the current R-squared<br />di 'rsqv' // as does this<br />regress mpg weight foreign<br />di 'rsqf' // the formula has the new R-squared<br />di 'rsqv' // this guy has the old one<br /><br />And the result is here:<br /> sysuse auto, clear<br />(1978 Automobile Data)<br /><br />. regress mpg weight<br /><br /> Source | SS df MS Number of obs = 74<br />-------------+------------------------------ F( 1, 72) = 134.62<br /> Model | 1591.9902 1 1591.9902 Prob > F = 0.0000<br /> Residual | 851.469256 72 11.8259619 R-squared = 0.6515<br />-------------+------------------------------ Adj R-squared = 0.6467<br /> Total | 2443.45946 73 33.4720474 Root MSE = 3.4389<br /><br />------------------------------------------------------------------------------<br /> mpg | Coef. Std. Err. t P>|t| [95% Conf. Interval]<br />-------------+----------------------------------------------------------------<br /> weight | -.0060087 .0005179 -11.60 0.000 -.0070411 -.0049763<br /> _cons | 39.44028 1.614003 24.44 0.000 36.22283 42.65774<br />------------------------------------------------------------------------------<br /><br />. local rsqf e(r2)<br /><br />. local rsqv = e(r2)<br /><br />. di 'rsqf' // this has the current R-squared<br />'rsqf' invalid name<br />r(198);<br /><br />end of do-file<br /><br />r(198);<br /><br />Why it says: 'rsqf' invalid name<br /><br />Please help!Longhttps://www.blogger.com/profile/13265830019277964567noreply@blogger.comtag:blogger.com,1999:blog-5290984163937382875.post-26828520187964773592009-10-30T19:07:09.219+02:002009-10-30T19:07:09.219+02:00This comment has been removed by the author.statamanhttps://www.blogger.com/profile/13749462261829425392noreply@blogger.comtag:blogger.com,1999:blog-5290984163937382875.post-381369989665724482009-10-30T15:52:02.413+02:002009-10-30T15:52:02.413+02:00thank you for this blog. i have often found it hel...thank you for this blog. i have often found it helpful.<br /><br />i just want to say that i'm disappointed by the title of this post (and some of its context). there are many skilled female stata users out there, including myself. saying that automating the code separates the "men from the boys" excludes women. why not just separate the "great coders from the good ones"?<br /><br />i know this is a touchy issue, and i appreciate your thoughtfulness on the topic.thought mongerhttps://www.blogger.com/profile/01324158941272911354noreply@blogger.comtag:blogger.com,1999:blog-5290984163937382875.post-44289556228377934732009-10-16T06:22:38.774+02:002009-10-16T06:22:38.774+02:00Actually, yes. I prepared some handouts for a shor...Actually, yes. I prepared some handouts for a short Stata course I gave. Will post a link in the main site soon.statamanhttps://www.blogger.com/profile/13749462261829425392noreply@blogger.comtag:blogger.com,1999:blog-5290984163937382875.post-90304286424428262182009-10-16T06:15:14.732+02:002009-10-16T06:15:14.732+02:00Your tutorial is excellent! I come from a programm...Your tutorial is excellent! I come from a programming background and this has brought me up to speed. One thing I am sorely lacking in understanding is how to build tables. Did you ever get around to writing that next step in the tutorial? If not, any example code you could send me? Thanks again.Jonathanhttps://www.blogger.com/profile/01624799131393081540noreply@blogger.comtag:blogger.com,1999:blog-5290984163937382875.post-11982326235286143282009-08-27T11:12:43.864+03:002009-08-27T11:12:43.864+03:00Hi Stataman,
thanks a lot for your sooooo usefull...Hi Stataman,<br /><br />thanks a lot for your sooooo usefull contribution. It is very clear and interesting and I am deadly looking forward to reading the next steps ! Using the output results and making nice tables might be sometimes pretty tricky, particularly with ecommands...<br />hope you will find some time !<br />cheers<br /><br />Marie Gmarthehttps://www.blogger.com/profile/13224083183016086041noreply@blogger.comtag:blogger.com,1999:blog-5290984163937382875.post-72437763622819120692009-08-06T19:11:20.895+03:002009-08-06T19:11:20.895+03:00Hi Michael,
Thanks! I'm glad you found this h...Hi Michael,<br /><br />Thanks! I'm glad you found this helpful.<br /><br />Roystatamanhttps://www.blogger.com/profile/13749462261829425392noreply@blogger.comtag:blogger.com,1999:blog-5290984163937382875.post-40336401614105548282009-08-02T05:02:35.620+03:002009-08-02T05:02:35.620+03:00Stataman: I want to post a follow up to my message...Stataman: I want to post a follow up to my message of a few weeks ago. After reading your tutorial on automation, I've been thinking how I might incorporate those ideas into my own work with Stata. I managed to recognize a couple of opportunities to use automation. But I needed to learn more about the syntax, application, etc. I found Larry Hamilton's text, "Statistics with Stata" in chapter 14 a very good follow up to your excellent primer. Reading your material is much easier than any text I think and it gave me a start in the new area (for me) of automation. Your comments about automation syntax being a language is spot on. It comes along with practice. Thanks.<br /><br />I'll be checking back to your website to see if you manage to write the final two sections. We appreciate your time in putting this together. It's made me more proficient for my doctorate research.Michaelhttps://www.blogger.com/profile/13277568790680242249noreply@blogger.comtag:blogger.com,1999:blog-5290984163937382875.post-26755990303742391442009-07-12T00:21:27.661+03:002009-07-12T00:21:27.661+03:00Good question, Michael.
First, let me say that wh...Good question, Michael.<br /><br />First, let me say that whenever you learn a new language it is looks at first as a waste of time, or even if not - it takes a lot of time and energy. But once you become more acquainted and experienced with the language, things are much faster and more efficient.<br /><br />Now, even after you will get to know the language, it won't always be better to write things generically and some times just copying a list of commands will do the job. Especially when you already experimented with the command line and got the job done.<br /><br />However, in many papers you see tables of regressions, for example, or of other statistics, and maybe some figures too. When the program gets big - in terms of running time or in terms of the lists of variables you use in your analysis and the number of commands you write - it becomes easier to just write a loop that will do the job. You can still do everything command after command, but it will make your code long, hard to edit and much more time-consuming. <br />Suppose now you want to do the whole table with a new control variable you didn't think of when you first ran the regressions. If you didn't write a loop, then you need to go over the lines and add the variable's name to each line. However, if you had a loop for all of the regressions, all you need to do is to add it to one place. It will be clearer, I hope, once I will find time to write the remaining steps here, but even copying your numbers to a table can be done automatically.<br /><br />Another place where you must use loops is Monte Carlo and other simulations. If you want to simulate samples of some random variable, you need to repeat it many times to learn more about your estimator (or other statistics you have in mind).<br /><br />Lastly, knowing the syntax of the language allows you to understand what some commands you find in Stata are actually doing. You can find those commands in the "ado" subfolder of where Stata is installed. You can then extend them if you don't have the command. For example, I think only the upcoming version of Stata 11 is going to systematically deal with GMM. However, you can think of ways to do, say, nonlinear IV regressions in earlier versions of Stata.<br /><br />I hope this gives you enough examples but, you know, it's a free country. If you don't buy it - ignore it. From my experience, the ability to generalize and automate my commands made me do stuff thrice as fast, and therefore freed up time to do more analysis.statamanhttps://www.blogger.com/profile/13749462261829425392noreply@blogger.comtag:blogger.com,1999:blog-5290984163937382875.post-36748400990467975512009-07-11T22:06:16.886+03:002009-07-11T22:06:16.886+03:00Stataman: I made it through your material for Step...Stataman: I made it through your material for Step 6 on automation. I am still struggling in understanding how that sort of automation saves significant time in economic and finance research. It seems to me that writing (or copying and pasting with some tweaking) separate Stata commands in a .do file would be as efficient as macros when it comes to running regressions and so forth on typical data sets we see in economics and finance. <br /><br />If you get a moment, can you provide a few examples where it is significantly more efficient to use macros/loops/etc. instead of using multiple commands in a .do file? The time to learn the syntax of Stata's macros/loops/etc. seems pretty significant. I currently can't see much time-savings. Thank you for your time and your website.Michaelhttps://www.blogger.com/profile/13277568790680242249noreply@blogger.comtag:blogger.com,1999:blog-5290984163937382875.post-67086589032394750972009-02-15T09:03:00.000+02:002009-02-15T09:03:00.000+02:00Hi again,I'm actually coming up on an interview in...Hi again,<BR/><BR/>I'm actually coming up on an interview in which I demonstrate my competency in Stata, for which I would LOVE to be able to show them excellent export abilities for the many regressions I'm generating. If you couldn't do post #7 can you possibly give me a few hints on which commands to check out or send me to another link? Much much appreciated,<BR/><BR/>Owen.Owen Martinhttps://www.blogger.com/profile/13192641032987397555noreply@blogger.com