Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Data used in Path Diagram in Stata News

    Data used in Path Diagram

    Could someone give me the link to the database used in illustrating gsem in the April?May/June vol 29 No 2 of The Stata News? Thanks.

  • #2
    Alberto: Better to start your own thread. It's confusing to present and future users to pepper threads with quite different questions.

    Comment


    • #3
      Alberto asked this same question of Stata Technical Support, so he has his answer already. However, in case others are interested, I am providing the information here. The short answer is that there is no database used in my example from the Stata News. The data is very nearly completely made up; it is a nice prerogative of writing examples. I've posted the code used to create the data below in case anyone wants to use it for their own examples. Just to underscore the point though, this is not in anyway data for real research.

      Code:
      webuse nlswork3, clear
      
      /* modify to create a fake outcome and some fake covariates */
      gen workstat = 2 if wks_ue >= 26 & wks_work < . & wks_ue < .
      replace workstat = 3 if wks_work < 26 & workstat==.
      replace workstat = 1 if workstat==. & wks_work <.
      
      label def workstat 1 "employed" 2 "unemployed" 3 "out of labor force"
      label values workstat workstat
      
      gen student = (age <= 18)
      set seed 103606
      by idcode: egen mgrade = max(grade)
      bys idcode (age): gen flag = ///
          min(round(runiform()*age),_N,max(0,mgrade-12)) if _n==1
      replace flag = mgrade-12 if mgrade > 12 & flag < mgrade & mgrade < .
      by idcode: replace student = 1 if _n<flag[1]
      /* end modifications */
      -- Rebecca

      Comment


      • #4
        Hi Rebecca,

        thank you for the example. I get an error trying to run it. Here is my code, which is basically just a copy of yours:

        Code:
        clear all
        set more off
        
        webuse nlswork3
        
        * Data Preparation *
        g workstat = 2 if wks_ue >= 26 & wks_work < . & wks_ue < .
        replace workstat = 3 if wks_work < 26 & workstat == .
        replace workstat = 1 if wks_work < . & workstat == .
        
        label def wkstat 1 "employed" 2 "unemployed" 3 "out of the labor force"
        label values workstat wkstat
        
        g student = age <= 18
        set seed 103606
        by idcode: egen mgrade = max(grade)
        bys idcode (age): gen flag = min(round(runiform()*age), _N, max(0,mgrade-12)) ///
            if _n == 1
        replace flag = mgrade - 12 if mgrade > 12 & flag < mgrade & mgrade < .
        by idcode: replace student = 1 if _n < flag[1]
        
        * End of Data Preparation *
        
        * Using employed as the base category, so we omit it
        gsem (2.workstat <- age i.race i.student i.msp #9;RI2[idcode]) ///
             (3.workstat <- age i.race i.student i.msp #9;RI3[idcode]), mlogit
        And The output is here


        I'm using Stata/SE 13.1 for Mac (64-bit Intel) Revision 24 Apr 2014
        Attached Files
        Last edited by Alfonso Sánchez-Peñalver; 29 Apr 2014, 11:35. Reason: Symbols in the code (great than, ampersand, etc...) had been converted into HTML tags, converting them back.
        Alfonso Sanchez-Penalver

        Comment


        • #5
          Alfonso,
          It looks like there is an error in the HTML version of the News. "#9;" was substituted for a line break when converting from PDF to HTML. This will be fixed. In the interim, if you do not have the printed version, you can view the PDF here http://www.stata.com/stata-news/statanews.29.2.pdf.

          For convenience, the gsem command is

          Code:
          gsem (2.workstat <- age i.race i.student i.msp RI2[idcode]) ///
          (3.workstat <- age i.race i.student i.msp RI3[idcode]), mlogit
          Regards,
          Rebecca

          Comment

          Working...
          X