Announcement

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

  • randomtag - count() with variable or local

    Hello!

    I want to use the command randomtag to get an exact number of obs for each treatment group.
    However, I don't get the count() to work with variable or local: count(var1) or count(`local').

    option count() invalid
    r(198);

    end of do-file

    r(198);


    I only get it to work with a number: count(#) where # is a typed in number.

    Question: Is there a way to get count() to work with a variable or a local?

    _______________________

    Description:
    I have 10 treatment groups, 12 strata, and over 20 000 obs. I want specific and uneven treatment group sizes. The relative treatment group sizes in shares are p1...p10.

    First I calculate the number of obs for each treatment group in each strata.
    (p1= size of each treatment group as share, N_strata=number of obs per strata.)

    * Treatment size (#) for treatment group 1, in each strata (1-10):
    gen s1 = floor(p1*N_strata) /* # obs in treatment 1*/

    Then I want to use the command randomtag with the numbers I just calculated above.
    However, I don't get the count() to work with variables or locals, which represent these numbers.

    * This doesn't work:
    randomtag if strata==1, count(s1) gen(T1_1)

    Error:
    option count() invalid
    r(198);

    end of do-file

    r(198);



    * This works, but here I manually type in the numbers in count()
    randomtag if strata==1, count(644) gen(T1_1)
    randomtag if strata==2, count(644) gen(T1_2)
    randomtag if strata==3, count(81) gen(T1_3)
    randomtag if strata==4, count(686) gen(T1_4)
    randomtag if strata==5, count(707) gen(T1_5)
    randomtag if strata==6, count(113) gen(T1_6)
    randomtag if strata==7, count(524) gen(T1_7)
    randomtag if strata==8, count(493) gen(T1_8)
    randomtag if strata==9, count(17) gen(T1_9)
    randomtag if strata==10, count(432) gen(T1_10)
    randomtag if strata==11, count(430) gen(T1_11)
    randomtag if strata==12, count(23) gen(T1_12)

    Thanks a lot for your help!
    Best regards,
    Louise

  • #2
    Perhaps the following sample will show you how to use a local macro as part of a command.
    Code:
    . sysuse auto, clear
    (1978 Automobile Data)
    
    . local n 4
    
    . list make in 1/4
    
         +---------------+
         | make          |
         |---------------|
      1. | AMC Concord   |
      2. | AMC Pacer     |
      3. | AMC Spirit    |
      4. | Buick Century |
         +---------------+
    
    . list make in 1/`n'
    
         +---------------+
         | make          |
         |---------------|
      1. | AMC Concord   |
      2. | AMC Pacer     |
      3. | AMC Spirit    |
      4. | Buick Century |
         +---------------+

    Comment

    Working...
    X