Rita Tang
  • NEW!
    NEW!  Connect Ideas Across Notes
    Save time and share insights. With Paragraph Citation, you can quote others’ work with source info built in. If someone cites your note, you’ll see a card showing where it’s used—bringing notes closer together.
    Got it
      • Create new note
      • Create a note from template
        • Sharing URL Link copied
        • /edit
        • View mode
          • Edit mode
          • View mode
          • Book mode
          • Slide mode
          Edit mode View mode Book mode Slide mode
        • Customize slides
        • Note Permission
        • Read
          • Only me
          • Signed-in users
          • Everyone
          Only me Signed-in users Everyone
        • Write
          • Only me
          • Signed-in users
          • Everyone
          Only me Signed-in users Everyone
        • Engagement control Commenting, Suggest edit, Emoji Reply
      • Invite by email
        Invitee

        This note has no invitees

      • Publish Note

        Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

        Your note will be visible on your profile and discoverable by anyone.
        Your note is now live.
        This note is visible on your profile and discoverable online.
        Everyone on the web can find and read all notes of this public team.

        Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

        Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

        Explore these features while you wait
        Complete general settings
        Bookmark and like published notes
        Write a few more notes
        Complete general settings
        Write a few more notes
        See published notes
        Unpublish note
        Please check the box to agree to the Community Guidelines.
        View profile
      • Commenting
        Permission
        Disabled Forbidden Owners Signed-in users Everyone
      • Enable
      • Permission
        • Forbidden
        • Owners
        • Signed-in users
        • Everyone
      • Suggest edit
        Permission
        Disabled Forbidden Owners Signed-in users Everyone
      • Enable
      • Permission
        • Forbidden
        • Owners
        • Signed-in users
      • Emoji Reply
      • Enable
      • Versions and GitHub Sync
      • Note settings
      • Note Insights New
      • Engagement control
      • Make a copy
      • Transfer ownership
      • Delete this note
      • Save as template
      • Insert from template
      • Import from
        • Dropbox
        • Google Drive
        • Gist
        • Clipboard
      • Export to
        • Dropbox
        • Google Drive
        • Gist
      • Download
        • Markdown
        • HTML
        • Raw HTML
    Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
    Create Create new note Create a note from template
    Menu
    Options
    Engagement control Make a copy Transfer ownership Delete this note
    Import from
    Dropbox Google Drive Gist Clipboard
    Export to
    Dropbox Google Drive Gist
    Download
    Markdown HTML Raw HTML
    Back
    Sharing URL Link copied
    /edit
    View mode
    • Edit mode
    • View mode
    • Book mode
    • Slide mode
    Edit mode View mode Book mode Slide mode
    Customize slides
    Note Permission
    Read
    Only me
    • Only me
    • Signed-in users
    • Everyone
    Only me Signed-in users Everyone
    Write
    Only me
    • Only me
    • Signed-in users
    • Everyone
    Only me Signed-in users Everyone
    Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- GA: UA-159972578-2 --- ###### tags: `計量經濟` `Econometrics` `Panel Data` `plm` `Random Effect Model` `Fixed Effect Model` # Panel Data Model (TSCS Data) + 閱讀 [Rpub版](https://rpubs.com/RitaTang/plm) + Reference: 1. [Econometrics Academy](https://sites.google.com/site/econometricsacademy/econometrics-models/panel-data-models) 2. CUHK Materials ## Content [1. 資料結構](#ch1) [2. 模型介紹](#ch2) [3. 模型選擇](#ch3) [4. 模型解釋](#ch4) ## <a id='ch1'></a> 1. What is panel data? + Structure in data: Individual & Time ![](https://i.imgur.com/fKI7LLa.png =60%x) + Prepare Data ```{r message=FALSE, warning=FALSE} library(plm) mydata<- read.csv("panel_wage.csv") attach(mydata) # 代表接下來都用同樣的df,呼叫變數時前面不用再打'mydata$' formula = lwage ~ exp + exp2 + wks + ed ``` + Variable List <table> <tr> <td> lwage </td> <td> log(Wage) </td> <td> Dependent Variable </td> </tr> <tr> <td> exp </td> <td> Experience </td> <td> Varying Regressor </td> </tr> <tr> <td> exp2 </td> <td> Experience^2 </td> <td> Varying Regressor </td> </tr> <tr> <td> wks </td> <td> Weeks worked </td> <td> Varying Regressor </td> </tr> <tr> <td> ed </td> <td> Education </td> <td> Time-invariant Regressor </td> </tr> </table> + Set as Panel Data ```{r} pdata <- pdata.frame(mydata, index=c("id","t")) ``` ## <a id='ch2'></a> 2. To deal with corrlations among error: Data Transform ### I. Estimators + OLS Pooled + Transformation: Nothing + No. obs: NT + **Ignores the unobserved heterogeneity of users** (possible association within groups) ```{r results='hide'} pooling <- plm(formula, data=pdata, model= "pooling") summary(pooling) # 跟lm一樣但忽略data structure ``` + Beween (individual) + Transformation: **Time average of all variable** + No. obs: N + Loss information ```{r results='hide'} between <- plm(formula, data=pdata, model= "between") summary(between) ``` + Within (individual) across time, Fixed Effect (FE) + Transformation: **Time-demean** + No. obs: NT + Individual specific effect (𝜶i) cancelled(扣掉人的效果) + No idiosyncratic error(error between an indivisual) + ![](https://i.imgur.com/prDdXtN.png) + Error(𝜶) is individual specific error + Error(e) is idiosyncratic error + **Time-invariant variable are dropped** ```{r results='hide'} fixed <- plm(formula, data=pdata, model= "within") summary(fixed) ``` <center> ![](https://i.imgur.com/5R8WkgO.png =80%x) (圖解Btween和Within之差異) </center> <br> + LSDV, Fixed Effects (FE):做個人的Dummy + First-Diff (FD) + Transformation: **One period difference** + No. obs: N(T-1) + Individual specific effect (𝜶i) cancelled + **Time-invariant variable are dropped** + No Constant(因為被減掉了) + 必須在strict exogeneity(嚴格外生性的)的前提成立下才能使用 ```{r results='hide'} firstdiff <- plm(formula, data=pdata, model= "fd") summary(firstdiff) # 沒有截距項,會把exp的係數打在(Intercept)中 ``` ![](https://i.imgur.com/OTlZvuc.png =85%x) <br> ![](https://i.imgur.com/n5ZuxtY.png =85%x) <center>(Why FE model is preferred to FD model)</center> <br> + Random Effect (RE) + Transformation: **Weighted average of between & within estimates** + ![](https://i.imgur.com/cAH1HRW.png) + theta(or Lamda)介於在0~1之間 + 愈接近0代表靠近Pooled OLS,愈接近1代表靠近within的方法 + 若個人效果(indivisual specific)不大,且模型沒有inconsistent(RE和FE都是Consistence)則選擇RE模型(More Effiecient) + No. obs: NT ```{r results='hide'} random <- plm(formula, data=pdata, model= "random") summary(random) ``` ### II. Situation + 在計量經濟中,最重要的是Consistence,再來才是Effiecience <table> <tr> <td> Estimator \ True model </td> <th> Pooled model </th> <th> RE model </th> <th> FE model </th> </tr> <tr> <th> Pooled OLS estimator </th> <td> Consistent </td> <td> Consistent </td> <td> Inconsistent </td> </tr> <tr> <th> Between estimator </th> <td> Consistent </td> <td> Consistent </td> <td> Inconsistent </td> </tr> <tr> <th> Within or FE estimator </th> <td> Consistent </td> <td> Consistent </td> <td> Consistent </td> </tr> <tr> <th> RE estimator </th> <td> Consistent </td> <td> Consistent </td> <td> Inconsistent </td> </tr> </table> ## <a id='ch3'></a> 3. Choose a Model <center> ![](https://i.imgur.com/xk6SQSU.png =65%x) (Flowchart for Choosing a Model) </center> <br> ![](https://i.imgur.com/GRNELxw.png =85%x) <br> ![](https://i.imgur.com/ZzwuUyQ.png =85%x) <br> + Heteroscedasticity: BP test ```{r message=FALSE, warning=FALSE} library(lmtest) bptest(pooling) ``` + Other Statistic test ```{r} ## LM test for random effects versus OLS plmtest(pooling) ## LM test for fixed effects versus OLS pFtest(fixed, pooling) ``` + Hausman test: FE v.s. RE + Can be calculated only for the time-varying regressors. + Significant: use the fixed effects. + Insignificant: use the random effects. ```{r} phtest(random, fixed) ``` ## <a id='ch4'></a> 4. Explaination <center> ![](https://i.imgur.com/vFaj4Fx.png =65%x) </center> + 不管是哪個 estimators 都顯示,較高的經驗和教育水準與較高的薪資水平有關 + 就各個模型而言 + 【Pooled OLS】跨過個人和時間,額外一年的工作經驗會導致薪資提高4% + 【Between】對有多一年工作經驗的人,其平均薪資比一般人高3% + 【Within】每增加一年的工作經驗,對經驗高於平均的人而言薪資會多11% + 【First differences】在第一年到下一年的期間,每增加一年的工作經驗,薪資會多11% + 【Random】每增加一年的工作經驗,對經驗高於平均的人而言薪資會多8% + 因為 Hausman test 顯示 FE & RE 兩者模型的係數顯著不同,因此我們選擇 FE 模型 + Rho 是 individual specific variation 的百分比,此例有非常高的比例 (FE: 98% & RE: 81%) 被 individual specific term 被解釋,剩餘不能解釋的是由於 idiosyncratic error + Rho 是個人的變異(因為在model裡面沒有放入individual) + 假設它帶有效果會跑到error裡面和真正的error混在一起(idiosyncratic) + Lambda 為 82%,因此 RE estimates 比 pooled estimates 更靠近 within estimates + FE把所有個人扣除所以R2比較大 + R-squares 顯示 between estimator 可以解釋 32% 的 between variation,而 FE & RE estimators 分別可以解釋 66% 和 63% 的 within variation

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Google Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully