大数据人|大数据第一社区

 找回密码
 注册会员

扫一扫,访问微社区

查看: 3520|回复: 0

一些Stata Tips汇总

[复制链接]
  • TA的每日心情
    奋斗
    2015-7-30 23:05
  • 签到天数: 12 天

    [LV.3]偶尔看看II

    852

    主题

    972

    帖子

    4804

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    积分
    4804
    QQ
    发表于 2015-11-19 19:40:53 | 显示全部楼层 |阅读模式
    Stata Tips:
    1. Don’t use the Stata do-file editor. Use Notepad++ or Crimson Editor instead, and add the
    requisite code to run do-files and selected parts of do-files
    2. Don’t use the tempting semi-colon delimiter. It doesn’t work so well in Mata. Make
    liberal use of /// instead if a line of code is too long. One important exception to this is
    when defining very long local or global macros. In that case you want to switch over to
    semicolon delimiting so you can split up the macro (see #3)
    3. Don’t let lines of code get too long. This makes it hard to read, both on the screen and
    especially when printed. Keep your code less than 85 characters per line, using ///
    when you have to wrap to the next line
    4. If you’re doing a foreach or forvalues loop, indent all the material between the brackets,
    then put a little comment after the closing bracket to tell the reader (i.e. your 6-monthsfrom-now-can’t-read-your-own-code self) what just ended. Same for if statements and so
    on. (even after a quietly { } block)
    5. Make liberal use of short programs and loops rather than repeating blocks of code with
    only minor changes. However…
    6. Make your do-files readable. Try to make sections that use macros reasonably and don’t
    over-abbreviate commands. Yes, it’s cool that s can substitute for save but this makes
    code hard to read.
    7. Write an introductory section in which you say what the do-file does (in fact, an outline
    can be very helpful), where it fits into the overall project (i.e. “This do-file,
    descriptive.do, follows data-cleanup.do and is followed by regressions.do); and what the
    key inputs and outputs are
    8. Make liberal use of comments! Again, the ideal is that someone who has never seen your
    project before could pick up your do-file and know what is going on, both in the bigpicture sense as well as what each section of code is doing.
    9. If you’re going to use a global macro, use the ${…} expander instead of just $.... .
    This is much easier to read, especially when nesting.
    10. Don’t use the = sign when defining macros! If so your macro will get truncated at ~255 (I
    think) characters which can mess you up.  For example:
    qui ls
    local MyVariables `r(varlist)’
    will put all your variables into the MyVariables local macro, but
    qui ls
    local MyVariables = “`r(varlist)’”
    will cut off after 255 characters
    原文地址:http://econweb.umd.edu/~guiteras/Stata Tips.pdf

    回复

    使用道具 举报

    您需要登录后才可以回帖 登录 | 注册会员

    本版积分规则

    关闭

    站长推荐上一条 /2 下一条


    id="mn_portal" >首页Portalid="mn_P18" onmouseover="navShow('P18')">应用id="mn_P15" onmouseover="navShow('P15')">技术id="mn_P37" onmouseover="showMenu({'ctrlid':this.id,'ctrlclass':'hover','duration':2})">前沿id="mn_P36" onmouseover="navShow('P36')">宝箱id="mn_P61" onmouseover="showMenu({'ctrlid':this.id,'ctrlclass':'hover','duration':2})">专栏id="mn_P65" >企业id="mn_Nd633" >导航 折叠导航 关注微信 关注微博 关注我们

    QQ|广告服务|关于我们|Archiver|手机版|小黑屋|大数据人 ( 鄂ICP备14012176号-2  

    GMT+8, 2024-3-19 11:14 , Processed in 0.285659 second(s), 31 queries .

    Powered by 小雄! X3.2

    © 2014-2020 bigdataer Inc.

    快速回复 返回顶部 返回列表