Announcement

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

  • SPSS code to Stata syntax

    Hi,

    I have a question about how to import a .txt file filled with a SPSS code into Stata. Is there in any way an option that stata can read this file or recode it into something stata compatible?

    Thank you very much!

    Code:
    utility=function(PF,RLSF,VIT,PAIN,MH,RL){
    Most=as.numeric()
    Most=ifelse(PF==3|RL==3|RL==4|SF==4|SF==5|PAIN==4|PAIN==5|MH==4|MH==5|VIT==4|VIT==5,1,0)
    
    PF1=as.numeric()
    RL_1=as.numeric()
    SF1=as.numeric()
    PAIN1=as.numeric()
    MH1=as.numeric()
    VIT1=as.numeric()
    Most1=as.numeric()
    
    for (i in 1:length(PF)){
    if(PF[i]==1)PF1[i]=0
    if(PF[i]==2)PF1[i]=0
    if(PF[i]==3)PF1[i]=-0.045
    
    if(RL[i]==1)RL_1[i]=0
    if(RL[i]==2)RL_1[i]=-0.063
    if(RL[i]==3)RL_1[i]=-0.063
    if(RL[i]==4)RL_1[i]=-0.063
    
    if(SF[i]==1)SF1[i]=0
    if(SF[i]==2)SF1[i]=-0.063
    if(SF[i]==3)SF1[i]=-0.066
    if(SF[i]==4)SF1[i]=-0.081
    if(SF[i]==5)SF1[i]=-0.093
    
    if(PAIN[i]==1) PAIN1[i]=0
    if(PAIN[i]==2) PAIN1[i]=0
    if(PAIN[i]==3) PAIN1[i]=-0.042
    if(PAIN[i]==4) PAIN1[i]=-0.077
    if(PAIN[i]==5) PAIN1[i]=-0.137
    
    if(MH[i]==1)MH1[i]=0
    if(MH[i]==2)MH1[i]=-0.059
    if(MH[i]==3)MH1[i]=-0.059
    if(MH[i]==4)MH1[i]=-0.113
    if(MH[i]==5)MH1[i]=-0.134
    
    if(VIT[i]==1)VIT1[i]=0
    if(VIT[i]==2)VIT1[i]=-0.078
    if(VIT[i]==3)VIT1[i]=-0.078
    if(VIT[i]==4)VIT1[i]=-0.078
    if(VIT[i]==5)VIT1[i]=-0.106
    
    if (Most[i]==0)Most1[i]=0
    if (Most[i]==1)Most1[i]=-0.077
    }
    QoL=1+PF1+RL_1+SF1+PAIN1+MH1+VIT1+Most1
    return(QoL)
    }

  • #2
    It would be a lot easier if you had SPSS create the file and then imported it into Stata. Is that an option? If not, there is a free SPSS clone you could try:

    https://www.gnu.org/software/pspp/
    -------------------------------------------
    Richard Williams, Notre Dame Dept of Sociology
    Stata Version: 17.0 MP (2 processor)

    EMAIL: [email protected]
    WWW: https://www3.nd.edu/~rwilliam

    Comment


    • #3
      Originally posted by Florian Maissan View Post
      I have a question about how to import a .txt file filled with a SPSS code into Stata. Is there in any way an option that stata can read this file or recode it into something stata compatible
      Richard gave good advice. To answer your question more directly: there is no software that translates SPSS syntax into Stata commands. For more information see this discussion on Statalist: http://www.statalist.org/forums/foru...-stata-do-file

      Comment


      • #4
        This does not look like any SPSS code I have ever seen. For example, I have never seen "ifelse" or "[i]" in SPSS. In fact, I see almost no lines of code in the sample that are syntactically valid SPSS statements. I have not used SPSS for about 10 years, so perhaps there is a bunch of new stuff, but that being said, I wonder if there is some confusion here. I suppose some of this might come from SPSS's macro or matrix languages, but I don't know.

        Comment


        • #5
          I've not used SPSS in the current millennium, but SPSS as I understand it allows Python code.

          Comment

          Working...
          X