14170:Programmingfor14.170:ProgrammingforEconomists1/12/2009-1/16/20091/12/2009-1/16/2009MelissaDellMattNotowidigdoPaulSchrimpfWhatis14.170?6170ilddttMITtitld“Itdti•6.170isaverypopularundergraduatecourseatMITtitled“IntroductiontoSoftwareEngineering.”Goalsofthecoursearethreefold:1.Developgoodprogramminghabits2.Learnhowtoimplementbasicalgorithms3.Learnvariousspecificfeaturesanddetailsofapopularprogramminglanguage(currentlyJava,buthasbeenPython,Scheme,C,C++inthepast)•Wecreatedaone-weekcourse14.170withsimilargoals:g1.Developgoodprogramminghabits2.Learnhowtoimplementbasicalgorithms3.Learnvariousspecificfeaturesanddetailsofseveralpopularprogramminglanguage(Stata,Perl,Matlab,C)•Courseinformation–COURSEWEBPAGE:([at]mitdotedu):–E-mails([at]mitdotedu):–mdell–noto–paulsp_COURSEOVERVIEWTd(MATT)BiSttItditSttToday(MATT):BasicStata,IntermediateStata,MLEandNLLSinStataTuesday(MATT):Mata,GMM,Largedatasets,numericalprecisionissuesWednesday(PAUL):Basic,IntermediateandAdvancedMatlabThursday(MATT,MELISSA):Perl,GISFriday(PAUL):IntrotoC,MoreC(C+Matlab,C+Stata))(seesyllabusformoredetails)Lecture1BasicStataLecture1,BasicStataBasicStataoverviewslide•Basicdatamanagement–Reading,writingdatasets–Generating,re-coding,parsingvariables(+regularexpressions,iftimeispermitting)–Built-infunctionsBuiltinfunctions–Sorting,merging,reshaping,collapsing•Programminglanguagedetails(controlstructures,variables,d)procedures)–forvalues,foreach,while,if,in–Global,local,andtemporaryvariables–Missingvariables(worstprogramminglanguagedesigndecisioninallofMissingvariables(worstprogramminglanguagedesigndecisioninallofStata)•Programming“bestpractices”Ct!–Comments!–Assertions–Summaries,tabulations(andLOOKatthem!)•Commonly-usedbuilt-infeatures–Regressionandpost-estimationcommands–OutputtingresultsDataManagement•Thekeymanualis“StataDataManagement”•Youshouldknowalmosteverycommandinthebookverywellbeforeyouprepareadatasetforaproject•Avoidre-inventingthewheel•WewillgooverthemostcommonlyneededcommandsWewillgooverthemostcommonlyneededcommands(butwewillnotgooverallofthem)•Type“helpcommand”tofindoutmoreinStata,e.g.“helpinfile”helpinfile•StandardRA“preparedataset”project1.Readindata2.Effectivelysummarize/tabulatedata,presentgraphs3.Preparedatasetforanalysis(generate,reshape,parse,encode,recode)4.PreliminaryregressionsandoutputresultsGettingstartedg•ThereareseveralwaystouseStata…ThereareseveralwaystouseStata…StatauserTexteditor(e.g.DOfileeditoroperatingsysteminterfaceemacs,TextPad)Windows(A)(B)UNIX/Linux(C)(D)•Irecommendstartingwith(A)I(D)bIfidthttdittb•Iuse(D)becauseIfindtheemacstexteditortobeveryeffective(andconducivetogoodprogrammingpractice)programmingpractice)Gettingstarted,(A)Gettingstarted,(A),con’tPress“Ctrl-8”toopeneditor!ReadingindataIfdataisalreadyinStatafileformat(thanksNBER!),weareallset…clearsetmemory500myuse“/proj/matt/aha80.dta”IfdataisnotinStataformat,thencanuseinsheetfortab-delimitedfilesorinfileorinfixforfixed-widthfiles(withorwithoutadatadictionary).AnothergoodoptionistouseStt/TfStat/Transferclearsetmemory500mihti“/j/tt/ikt/dttt”tbinsheetusing“/proj/matt/cricket/data.txt”,tabclearsetmemory500mifi///infix///intyear1-4///bytestatefip14-15///bytesex30///bhk5354///bytehrswork53-54///longincwage62-67///usingcps.datinsheetdataplayeryearroundpickpositionheightweightseasonsalaryestimatedAndrewBogut20051st1stC84245200643405200MarvinWilliams20051st2ndF81230200638835600DeronWilliams20051st3rdG75210200634874000ChrisPaul20051st4thG75175200631442400RaymondFelton20051st5thG73198200628473600MtllWbt20051t6thGF81210200625861200MartellWebster20051st6thG-F81210200625861200CharlieVillanueva20051st7thF83240200623608800ChanningFrye20051st8thF-C83248200621628800IkeDiogu20051st9thF80250200619881600AndrewBynum20051st10thC84285200618886800YaroslavKorolev20051st12thF81203200617044800YaroslavKorolev20051st12thF81203200617044800SeanMay20051st13thF81266200616192800RashadMcCants20051st14thG76207200615384000AntoineWright20051st15thG-F79210200614613600JoeyGraham20051st16thG-F79225200613884000DannyGranger20051st17thF80225200613189200ayGage005stt80500638900GeraldGreen20051st18thF80200200612530400HakimWarrick20051st19thF81219200611965200JuliusHodge20051st20thG79210200611487600infixdatainfixdata196502513581109002513580101661100111003341000002488000000196502513581109002513580201582100111003102400002180002000196502513581109002513580201582100111003102400002180002000196502513581109002658910301162100613105222000000030000000196502513581109003238430301341100615007102400007259005250196502513581109002513580101651100101001341000005000005000196502513581109002513580101651100101001341000005000005000196502513581109002513580201552100110003102400004200004200196502464591109002464590101561100111003102540004500004500196502464591109002464590201532100112004311000000000000000196502464591109002228200301181100614106331000000000000000196502464591109002228200301181100614106331000000000000000196502563361109002563360101681100106002212000005067004827196502563361109002563360201602