Announcement

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

  • rescale variables

    Hi everybody! I have to rescale 10231 random numbers created by 'gen r1=runiform (0,1)' . 0 would correspond to 20148, while 1 to 20300.Moreover, I would like the rescaled variable to take only integer numbers . May you please help me in understanding which command to use to do this? thanks a lot!
    Giulia

  • #2
    You may try this:

    Code:
    gen float myseq = seq(), from(20148) to(20300) block(1)
    Best regards,

    Marcos

    Comment


    • #3
      Originally posted by Marcos Almeida View Post
      You may try this:

      Code:
      gen float myseq = seq(), from(20148) to(20300) block(1)
      Thanks so much for your help! actually, do I have to replace seq() with my variable? When I try this in stata it claims that the option before and to is not allowed with gen.
      Thanks again

      Comment


      • #4
        seq() is an egen function. Marcos Almeida typed gen but meant egen.

        That aside, I don't understand the question. 10231 random numbers are probably all distinct. What is your rule for the mapping to 153 distinct integers?

        Comment


        • #5
          Originally posted by Nick Cox View Post
          seq() is an egen function. Marcos Almeida typed gen but meant egen.

          That aside, I don't understand the question. 10231 random numbers are probably all distinct. What is your rule for the mapping to 153 distinct integers?
          hi, thanks a lot for you answer. I will try to explain to you what my aim is. I created 10231 random numbers fro the command 'gen r1=runiform (0,1)', which obviously creates values among 0 and 1. However, I need to convert this numbers into dates for my analysis, particularly from 1 march 2015 to 31 july 2015, and using the command gen edate = mdy(month, day, year) I found that they correspond to 20148 and 20300. For this reason, I think I should convert my variable into integer numbers, so that I can transform them in dates afterwards.
          I don't know if I were able to properly explain the goal, but thanks a lot for your help, I will try with 'egen'.
          Just a final question, is it the same creating a random sequence from a uniform distribution and rescale it, or just create a sequance from 20148 to 20300 as I think this command does?
          Thanks a lot again
          Giulia
          Last edited by giulia Cescon; 06 Apr 2018, 05:13.

          Comment


          • #6
            I don't think you've answered my question about your mapping rule, but

            Code:
            gen date = 20148 + floor(153 * r1)
            may help. It won't guarantee either equal frequencies or that every distinct date occurs.

            I don't see that egen is relevant to your problem at all if you want some element of randomness. You haven't explained why you do in any case.

            Comment


            • #7
              Originally posted by Nick Cox View Post
              I don't think you've answered my question about your mapping rule, but

              Code:
              gen date = 20148 + floor(153 * r1)
              may help. It won't guarantee either equal frequencies or that every distinct date occurs.

              I don't see that egen is relevant to your problem at all if you want some element of randomness. You haven't explained why you do in any case.
              Excuse me. I will try to explain it; I am making an analysis on data coming from a survey considering 10231 individuals. However, replies from respondents were obtained from the 1st of march up to the 31 of July, but I do not have the specific date in which every person replied. I really need to have a specific date for every observation; therefore, my supervisor suggested me to assign a random number from the uniform distribution (0,1) to every respondent, then rescale it so that these numbers range from 20148 to 20300 (i.e. the range of time in which the respondents replied to the survey) and then transform it into a date.. That was the reason why I tried to rescale the number I got from the random distribution instead of creating a sequence..

              Comment


              • #8
                I really meant - egen - not - gen -, and I copied and pasted the command, after having tested it with a toy example. Unfortunately, the "e" got out of my "copy" command. Thanks to Nick for highlighting the mistype.
                Last edited by Marcos Almeida; 06 Apr 2018, 05:34.
                Best regards,

                Marcos

                Comment


                • #9
                  I think #6 is compatible with #7 but


                  Code:
                  gen wanted = runiformint(`=mdy(3, 1, 2015)', `=mdy(7, 31, 2015)')
                  is a direct solution.

                  Comment


                  • #10
                    Originally posted by Nick Cox View Post
                    I think #6 is compatible with #7 but


                    Code:
                    gen wanted = runiformint(`=mdy(3, 1, 2015)', `=mdy(7, 31, 2015)')
                    is a direct solution.
                    That's perfect!! Thanks a lot!!

                    Comment


                    • #11
                      That said, it is not clear that uniform distribution is very plausible here. Were all surveys distributed at the same time? Were there reminders? If you don't know dates, how does it help anything to guess them randomly?

                      Comment


                      • #12
                        Originally posted by Nick Cox View Post
                        That said, it is not clear that uniform distribution is very plausible here. Were all surveys distributed at the same time? Were there reminders? If you don't know dates, how does it help anything to guess them randomly?
                        yes,There were some remindersdueing the period.. however, I don't think that they were all distributed at the same time; of course, this would be very difficult. This has been suggested by my supervisor in order to try to lower the measurement errors to create a stronger instrument.. I am perfectly aware that these assumptions may not be reasonable in reality.. thanks a lot for your suggestion, however!

                        Comment

                        Working...
                        X