Announcement

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

  • Converting NIS database load program from SAS to STATA do file

    Hello everyone,

    I want to use the year 2003 of NIS database (Nationwide Inpatient Sample) in Stata but unfortunately they don't provide the so called 'load program' file —which is basically a do file for recoding and labeling the .asc format file— for Stata for this particular year. I tried to translate it myself but was afraid that I may make a mistake which can result in incorrect analyses later.

    This is the load program for 2003 in SAS:
    https://www.hcup-us.ahrq.gov/db/nation/nis/tools/pgms/SASload_NIS_2003_SEVERITY.sas​
    you can right click and download the file. Also, I have attached the .txt format here.

    I greatly appreciate it if anyone can help me in this regard.

    Thank you.

    Reza
    Attached Files
    Last edited by Reza Hosseini; 23 Nov 2015, 18:13.

  • #2
    Well
    • for the first chunk, search on -label define- and -label values-
    • for the second, search on -label variable-
    • and for the third chunk, -infix-

    Comment


    • #3
      Originally posted by ben earnhart View Post
      Well
      • for the first chunk, search on -label define- and -label values-
      • for the second, search on -label variable-
      • and for the third chunk, -infix-
      Thank you! Could you please give one example of each?

      Comment


      • #4
        here's an infix command that should probably work. You get that to work and I'll give you examples of the others (though the help files should be adequate, except maybe for infix). As it turned out, you linked to the command file, not the raw data. So my commands read *everything* as strings. You will want to either modify my syntax, or provide a link to the raw data.

        also -- the #delim ; option is cool and useful when you have really long commands.

        Code:
        cd c:\data\work
        clear
        
        #delim ;
        infix
        str    KEY        1    -    14
        str    HOSPID        15    -    19
        str    APRDRG        20    -    23
        str    APRDRG_Risk_Mortality        24    -    25
        str    APRDRG_Severity        26    -    27
        str    APSDRG        28    -    32
        str    APSDRG_Charge_Weight        33    -    42
        str    APSDRG_LOS_Weight        43    -    52
        str    APSDRG_Mortality_Weight        53    -    62
        str    CM_AIDS        63    -    64
        str    CM_ALCOHOL        65    -    66
        str    CM_ANEMDEF        67    -    68
        str    CM_ARTH        69    -    70
        str    CM_BLDLOSS        71    -    72
        str    CM_CHF        73    -    74
        str    CM_CHRNLUNG        75    -    76
        str    CM_COAG        77    -    78
        str    CM_DEPRESS        79    -    80
        str    CM_DM        81    -    82
        str    CM_DMCX        83    -    84
        str    CM_DRUG        85    -    86
        str    CM_HTN_C        87    -    88
        str    CM_HYPOTHY        89    -    90
        str    CM_LIVER        91    -    92
        str    CM_LYMPH        93    -    94
        str    CM_LYTES        95    -    96
        str    CM_METS        97    -    98
        str    CM_NEURO        99    -    100
        str    CM_OBESE        101    -    102
        str    CM_PARA        103    -    104
        str    CM_PERIVASC        105    -    106
        str    CM_PSYCH        107    -    108
        str    CM_PULMCIRC        109    -    110
        str    CM_RENLFAIL        111    -    112
        str    CM_TUMOR        113    -    114
        str    CM_ULCER        115    -    116
        str    CM_VALVE        117    -    118
        str    CM_WGHTLOSS        119    -    120
        str    DS_DX_Category1        121    -    125
        str    DS_LOS_Level        126    -    127
        str    DS_LOS_Scale        128    -    139
        str    DS_Mrt_Level        140    -    141
        str    DS_Mrt_Scale        142    -    153
        str    DS_RD_Level        154    -    155
        str    DS_RD_Scale        156    -    167
        str    DS_Stage1        168    -    171
        
        using SASload_NIS_2003_SEVERITY.sas.txt;

        Comment


        • #5
          Upon examining the syntax more closely, their PROC FORMAT statements are more about declaring missing values than value labels. So here's an example of the PROC FORMAT chunk. This will only work after you turn *off* the #delim ; and you -destring- your variables. I apologize for being difficult to interpret, but if translation were easy, we'd have programs for it like StatTranser

          example:
          INVALUE N2PF '-9' = .
          '-8' = .A '-6' = .C '-5' = .N translates to:
          Code:
          replace N2PF=. if N2PF==-9
          replace N2PF=.a if N2PF==-8
          replace N2PF=.c if N2PF==-6
          replace N2PF=.n if N2PF==-5
          Last edited by ben earnhart; 23 Nov 2015, 19:45.

          Comment


          • #6
            finally, their ATTRIB statements can be resolved to:
            Code:
            label variable KEY "HCUP record identifier"

            Comment


            • #7
              So all the ingredients are here for a successful resolution to your problem. If you can't get it to work, let me know and I'll clarify tomorrow. I'd say an hour or two of trying with what I laid out should be plenty -- beyond that, and I failed to communicate and it's my fault.

              Comment


              • #8
                Originally posted by ben earnhart View Post
                So all the ingredients are here for a successful resolution to your problem. If you can't get it to work, let me know and I'll clarify tomorrow. I'd say an hour or two of trying with what I laid out should be plenty -- beyond that, and I failed to communicate and it's my fault.
                Thank you so so much! I will work on these and will update you tomorrow.

                Comment


                • #9
                  Originally posted by ben earnhart View Post
                  So all the ingredients are here for a successful resolution to your problem. If you can't get it to work, let me know and I'll clarify tomorrow. I'd say an hour or two of trying with what I laid out should be plenty -- beyond that, and I failed to communicate and it's my fault.
                  It worked perfectly! Thank you again.

                  Comment


                  • #10
                    Glad you got it to work. Were you able to set missing values and attach labels as well?

                    Comment


                    • #11
                      Originally posted by ben earnhart View Post
                      Glad you got it to work. Were you able to set missing values and attach labels as well?
                      Yes. For years beyond 2003, they provide the load program file for Stata as well. So, I used the 2004 one as a reference for 2003 labels and dealing with missing values. Except some minor changes. they are almost identical.

                      Comment


                      • #12
                        What's the link to that post-2003 program, Reza?
                        Steve Samuels
                        Statistical Consulting
                        [email protected]

                        Stata 14.2

                        Comment


                        • #13
                          Originally posted by Steve Samuels View Post
                          What's the link to that post-2003 program, Reza?
                          Here it is:
                          https://www.hcup-us.ahrq.gov/db/nati...taloadprog.jsp

                          Comment


                          • #14
                            Thank you, Reza.
                            Steve Samuels
                            Statistical Consulting
                            [email protected]

                            Stata 14.2

                            Comment


                            • #15
                              Just wondering if anyone had Load files for the HCUP NIS 2000-2003 database that they would be willing to share, rather than recreating the wheel. For some reason they HCUP only provides stata load programs for 2004-2014

                              Comment

                              Working...
                              X