Announcement

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

  • Problems converting a string to numeric from an Excel file

    Hello

    I have been given an Excel file which has a logistic outcome variable (AR, label "Was the scheduled PRO completed electronically") which came across to Stata from Excel as a string variable. I have tried to encode it to a numeric variable (called "eprocom") which seems to look ok in the dataset but Stata keeps saying "the outcome does not vary" even if I put it in a model with no predictors, whcih shouldn't be affected by missing values in the independent variables.

    If you look at how dataex captures the variable, it's doing something funny and storing it as all 2's for some reason-a problem with labelling somehow which I have not requested.

    Code:
    * Example generated by -dataex-. For more info, type help dataex
    clear
    input byte WasthescheduledPROcompleted str85 IfPRONOTcompletedreasonpro str1 AR str127 IfNOTcompletedelectronically long eprocom
    1 "." "0" "Not technologically confident to use the app/difficulty with using the app" 2
    1 "." "0" "Not technologically confident to use the app/difficulty with using the app" 2
    1 "." "0" "Not technologically confident to use the app/difficulty with using the app" 2
    1 "." "0" "More convenient for participant"                                            2
    1 "." "0" "More convenient for participant"                                            2
    1 "." "0" "More convenient for participant"                                            2
    1 "." "0" "Participant does not have the required device to install the app"           2
    1 "." "0" "Participant does not have the required device to install the app"           2
    1 "." "0" "NO EPROS"                                                                   2
    1 "." "0" "NO EPRO"                                                                    2
    1 "." "0" "More convenient for participant"                                            2
    1 "." "0" "Participant does not have the required device to install the app"           2
    1 "." "0" "Internet connection/availability problems"                                  2
    1 "." "0" "More convenient for participant"                                            2
    1 "." "0" "More convenient for participant"                                            2
    1 "." "0" "PT REQUIRED INTERPRETER TO ANSWERE QUESTIONS"                               2
    1 "." "0" "PT REQUIRED AN INTERPRETER TO COMPLETE"                                     2
    1 "." "0" "More convenient for participant"                                            2
    1 "." "0" "Participant does not have the required device to install the app"           2
    1 "." "0" "More convenient for participant"                                            2
    end
    label values eprocom eprocom
    label def eprocom 2 "0", modify
    When I tabulate my "eprocom" variable it makes sense:
    Was the
    scheduled
    PRO
    completed
    electronica
    lly? Freq. Percent Cum.
    . 410 23.10 23.10
    0 1,320 74.37 97.46
    1 45 2.54 100.00
    Total 1,775 100.00
    But I can't use the variable in models without the "outcome does not vary" error message.

    Not sure what is going on here.

    Help appreciated and thanks in advance.

    Regards

    Chris

  • #2
    So I may have figured this out:

    Code:
     label list eprocom
    eprocom:
               1 .
               2 0
               3 1
    and then

    Code:
     recode eprocom (1=.) (2=0) (3=1),gen(eprocom_n)
    and now eprocom_n works as an outcome variable.

    Thanks for any advice anyway about this frustrating issue.

    Regards

    Chris

    Comment


    • #3

      Code:
      gen wanted = eprocom - 2 if eprocom != 1
      would be another way to do it. A wanted side-effect would be that the new variable is missing if the existing variable is 1.

      Comment


      • #4
        Thanks Nick.
        Your advice is always appreciated.
        Coming back to Stata after romances with R and SAS!
        Regards
        Chris

        Comment

        Working...
        X