Announcement

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

  • creating new variable

    Hello Stata users:

    I am looking to create a new variable (Number) that will count the number of members present in an existing room at a particular time.

    Attached is an example of my data and what I am looking to do.

    Thanks so much for your help.

    Attached Files

  • #2
    Please see

    0. The FAQ Advice, especially the point that MS Word file formats are not universally readable by Statalist members.

    1. Upstream and downstream from http://www.stata.com/statalist/archi.../msg01186.html

    2. http://www.stata-journal.com/article...article=dm0068

    Comment


    • #3
      Cross-posted at http://www.talkstats.com/showthread....om-Stata-users

      Please see the FAQ for our policy about cross-posting which is that you tell us where us you posted a question.

      Comment


      • #4
        Nick,
        Thank you for your reply. I see the FAQ for the statalist policy now, which I should have reviewed prior to posting. I will make sure to follow the protocol . Thank you also for referring me to the other similar question. However, my data set is more complicated than the example you list and I am still stuck. Are you able to refer me to any other examples? Thanks again.

        Comment


        • #5
          Code:
          clear all
          set more off
          
          *-----example data -----
          
          set obs 12
          
          gen room = "red"
          gen id = cond(_n < 4, 1, cond(_n > 8, 3, 2))
          
          gen start = cond(_n < 4, 2, cond(_n > 8, 0, 3))
          format start %td
          
          bysort id: gen stay = start + _n - 1
          format stay %td
          
          list, sepby(id)
          
          *----- what you want -----
          
          * number of people staying any particular day (relative to -stay-)
          bysort room stay: gen numst = _N
          
          * indicator == 1 if there's another person when any one person arrives
          bysort room id (stay): gen indicat = (numst[1] > 1)
          
          list, sepby(id)
          numst[1] has the number of people staying on each person's entry date. So if there is more than one person (i.e. the person herself), then there was someone else already in the room.
          Last edited by Roberto Ferrer; 22 May 2014, 20:30.
          You should:

          1. Read the FAQ carefully.

          2. "Say exactly what you typed and exactly what Stata typed (or did) in response. N.B. exactly!"

          3. Describe your dataset. Use list to list data when you are doing so. Use input to type in your own dataset fragment that others can experiment with.

          4. Use the advanced editing options to appropriately format quotes, data, code and Stata output. The advanced options can be toggled on/off using the A button in the top right corner of the text editor.

          Comment


          • #6
            Clyde,

            For future questions, please post a Stata dataset file instead of a MS Word file.
            You should:

            1. Read the FAQ carefully.

            2. "Say exactly what you typed and exactly what Stata typed (or did) in response. N.B. exactly!"

            3. Describe your dataset. Use list to list data when you are doing so. Use input to type in your own dataset fragment that others can experiment with.

            4. Use the advanced editing options to appropriately format quotes, data, code and Stata output. The advanced options can be toggled on/off using the A button in the top right corner of the text editor.

            Comment

            Working...
            X