您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 管理学资料 > stata讲义(初级-中级)
初级部分Lecture1UsingdirectoriestoorganizeyourworkYoucanfindoutwhatdirectoryyou'reinbytyping.pwdF:\StataStuffTofindwheretheofficialStatadirectoryis,type:.sysdirSTATA:C:\Stata8\UPDATES:C:\Stata8\ado\updates\BASE:C:\Stata8\ado\base\SITE:C:\Stata8\ado\site\PLUS:c:\ado\plus\PERSONAL:c:\ado\personal\OLDPLACE:c:\ado\Youdon'twanttouseStatafromtheofficialStatadirectoryoranysubdirectoryofitbecausetheStatadirectoryisonlyforofficialStatasoftware.Soifyougotthesameoutputfrom.pwdand.sysdir,youwillneedtochangedirectories:YoucanuseStata'smkdircommandtocreatedirectories,oryoucandoitoutsideofStatausinganymethodallowedbyyouroperatingsystem.IfyouwantedtomakeadirctoryontheFdriveusingStata,type:.cdF:\F:\.mkdirStataStuff2.cdStataStuff2F:\StataStuff2Statacanunderstandblanksinfilenamesaslongasthewholenameisindoublequotes.ForexampleifyouwantedtonamethefileStataStuff2,youshouldhavetyped:.cdF:\F:\.mkdir“StataStuff2”.cd“StataStuff2”F:\StataStuff2Tonowgotothedirectorywherewesavedthedatasets,type:.cdF:\StataStuffF:\StataStuffDealingwithfilesYouprobablyknowhowtoseethecontentsofadirectory,erasefilesinadirectory,copyfilesfromoneplacetoanother,andexaminethecontentsofafileusingyouroperatingsystem.YoucandothisfromStata,too,andsometimesthisisconvenient.Type:.dirtolistthecontentsofthecurrentdirectory.Type.dir*.dtatolistthefiles,ifany,thathavethesuffix.dtawhichindicatesaStatafile.Ifthefilemyfile.xyzisinthecurrentdirectory,youcanerasethefilebytyping:.erasemyfile.xyzYoucancopyafilefromwithinStatawiththecopycommand:.copymyfile.abcmycopy.bakthiscopiesmyfile.abcinthecurrentdirectorytomycopy.bak(alsointhecurrentdirectory).Thiscancomeinhandywhenyouwanttomakeabackupcopyofanimportantfilebeforemakingchangestothefile.And,ofcourse,youcanspecifydirectoriesalongwiththefilename,especiallyusefulifwantingtodealoutsidethecurrentdirectorybutcanalwaysbeused.Ifyoutype:.copyC:\data\myfile.datF:\statastuff\data\stuff.datthefilemyfile.datintheC:\datadirectorywillbecopiedtothefilestuff.datintheF:\statastuff\datadirectory.YoucanalsouseStatatoviewthecontentsofafile.Type:.typemydata.rawtodisplaythecontentsofthefilemydata.rawintheStataResultswindow.FilenamesinStataIfyoubegininthedirectoryF:\dataandtype:.usemyfile.xyzItusesthefileF:\data\myfile.xyz,butitdoesnotchangethecurrentdirectory.Thereforethatcommandisequivalenttotyping:.useF:\data\myfile.xyzThedefaultsuffixforStatadatasetsis.dta.ThisdoesnotmeanyourStatadatasetshavetoendwith.dta,butifyoudonotspecifyotherwise,theywill.Typing:.usemyfileisthesameastyping:.usemyfile.dtaThebasicsofStataStataisaninteractivedataanalysispackagethatprovides•datamanagement•statisticalanalysis•graphicsDespitethevariousaccessoriesprovidedbyStataforwindowedoperatingsystems,includingseveralhundreddialogboxestohelpyoucreatealmostanyStatacommand,Stataisatitsheartcommanddriven.YoutypetypicallyshortcommandstoStata'sdotprompt,suchas:.summarizegdpThefactthatyouareworkingwithacopyofthedataisimportant.Whenyouusefilename,thedataiscopiedfromdisktomemory,andthefileisclosed.Youcandowhateveryouwanttothedatainmemory,andthepermanentcopyondiskisunaffected.Theonlywaytochangethepermanentcopyofthedataistosaveit.ToloadadatasetthathassomehowbeensavedinStataformatpreviously:.use1998Data(1998Data)or.use1998Data,clear(1998Data)Inthefirstform,usefilenamesaystoloadthedata,butStatawillrefuseif(1)thereissomethinginmemoryand(2)thatsomethinghasnotbeensavedondisk.usefilename,clearsaystoloadthedatanomatterwhat,discardingwhateverisinmemory,evenifithasnotbeensaved.Tosave,type:.save1998Dataor.save1998Data,replaceWithoutthereplaceoption,thefilemustnotalreadyexist.Ifitdoes,Statawillrefusetooverwriteit.Withthereplaceoption,thefilemayexistornot.Ifthefiledoesexist,itwillbeoverwritten.HowStataconceptualizesdataStata'sconceptofdataisthatofatable:Thecolumnsarethevariables--theyhavenames--andtherowsaretheobservations--theyarenumbered.Torefertoanindividualcellofthetable,2notationsare:varname[6]varnamein6wherevarnameisthenameofthevariableand6istheobservationnumber.Ifanameistoolong,omitedlettersarereplacedwith~.Tosummarizeadataset,type:.describeContainsdatafrom1998Data.dtaobs:71998Datavars:524Jul200312:24size:280(99.9%ofmemoryfree)-------------------------------------------------------------------------------storagedisplayvaluevariablenametypeformatlabelvariablelabel-------------------------------------------------------------------------------countrystr13%13sCountrypoplong%12.0gPopulationgdpfloat%9.0gGDP(billions)uestr11%11sUnemploymenttradefloat%9.0gTrade(%ofGDP)-------------------------------------------------------------------------------Sortedby:Tolistthedatainatable,type:.list+----------------------------------------------------------------+countrypopgdpuetrade----------------------------------------------------------------1.China1242179968900.24873.09999990539.206782.France583982001649.34911.8000001949.593333.Japan1264100005345.3034.09999990520.24694.Mexico95252432337.18062.29999995263.619635.Switzerland7110000319.86213.59999990576.67068---------------------------------------------------------
本文标题:stata讲义(初级-中级)
链接地址:https://www.777doc.com/doc-1795890 .html