Announcement

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

  • Transforming continuous variables

    Hello,
    I have continuous variables age and BMI. I need to apply this but I do not understand what it means:

    Code:
    double dage = age;
    dage=dage/10;
    double age_1 = pow(dage,-2);
    double age_2 = dage;
    double dbmi = bmi;
    dbmi=dbmi/10;
    double bmi_1 = pow(dbmi,-2);
    double bmi_2 = pow(dbmi,-2)*log(dbmi);
    Can anyone advise how I do this in stata? I do not understand why the age and bmi have been split into two variables age_1 and age_2 and how I create this in stata?

  • #2
    You need to tell us what language this is! Dothraki? Klingon? Recently you posted a question about C++ but you shouldn't presume that people both read and remember that.

    You need to tell us what bmi and age are. My guess is that they would be variables in Stata (i.e. columns in spreadsheetspeak). and on that guess

    Code:
    gen double dage = age/10 
    gen double age_1 = 1/(age^2) 
    gen double dbmi = bmi/10 
    gen double bmi_1 = 1/(dbmi^2)  
    gen double bmi_2 = log(dbmi) / dbmi^2
    I haven't given you code for age_2; it is just a clone of another variable and has no obvious point.

    I am making guesses here that log() means natural logarithm and pow() is a powering function. Translating from a language I have never used is more dangerous for you than for me.

    I think you need a collaborator who knows C++ and Stata well, and as your previous thread didn't seem to produce a volunteer you may need to see elsewhere.

    Comment


    • #3
      Hi Nick,

      Thanks that's great I think you are right! I am almost there with it now. I just have one query and then I can test if I have done it right,

      What does this mean:

      Code:
        
       double a=0;   
       a += age_1 * -8.1388109247726188000000000
      Is there a way to make sense of this in STATA?

      Thanks

      Comment


      • #4
        That's a slightly bizarre way of writing

        Code:
        gen double a = age_1 * -8.1388109247726188
        In many languages

        a += whatever

        means "take a, add whatever and that's the new a" but adding something to zero has, in my experience, always been equivalent to assigning something in the first place.


        Which extraordinary expert thinks that measurements in this field are precise to 26 significant figures? I doubt that even specialised measurements in physics can boast that.

        Comment


        • #5
          Thanks that's helpful.

          Apologies but I am also unsure with how to deal with a categorical variable (ethnicity). I have the variable coded 1-9 and need to transform to for some reason 10 options.

          Code:
           double Iethrisk[10] = {
          0,
          0,
          0.2804031433299542500000000,
          0.5629899414207539800000000,
          0.2959000085111651600000000,
          0.0727853798779825450000000,
          -0.1707213550885731700000000,
          -0.3937104331487497100000000,
          -0.3263249528353027200000000,
          -0.1712705688324178400000000 }

          Comment


          • #6
            I can't see that anyone can tell how to deal with that in Stata without knowing the context.

            Comment


            • #7
              It is a conditional array

              Comment


              • #8
                Sorry; same answer from me. That's a name, not a context implying code.

                Comment


                • #9
                  Thanks I've sorted it now using the matrix command.
                  Last edited by Alex Williams; 21 Nov 2019, 08:28.

                  Comment


                  • #10
                    Thank you Nick I am on the final line of the code now do you know how to interpret this in stata where pow = ^
                    Thanks

                    Code:
                     double score = 100.0 * (1 - pow(survivor[surv], exp(a)) )
                    Last edited by Alex Williams; 21 Nov 2019, 08:46.

                    Comment


                    • #11
                      I can't guess, sorry, and won't be contributing further to this thread.

                      But it would be good practice for you to tell people about cross-posting as here:

                      https://www.statalist.org/forums/for...1525752-arrays

                      Comment

                      Working...
                      X