Announcement

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

  • rank problem

    hello teacher
    I have a question need help, I want to simulate the SAS code to separate "size" to two groups per year (yymm is time variable)

    ///////(SAS code)///////
    PROC RANK DATA=stock GROUPS=2 OUT=rout1;
    VAR size;
    RANKS sr;
    BY yymm;
    RUN;
    ////////////////////////////////////
    My Stata code
    bys yymm: xtile sr=size,np(2)

    Stata reply: (xtile may not be combined with by )


    so I change code
    xtile sr=size,nq(2) by(yymm)

    Stata reply: (option by() not allowed )

    so.. what can I do? , please help
    Last edited by Curtis Chou; 01 Jul 2020, 01:30.

  • #2
    Would it be something like
    Code:
    bysort yymm: egen double median = pctile(size)
    generate byte sr = size >= median if !mi(size)

    Comment


    • #3
      thanks, teacher
      May I ask about the code
      first
      bysort yymm: even "double" median = pctile(size)
      why does add "double"?
      why use pctile instead of xtile

      second
      generate byte sr = size >= median if !mi(size)
      what is byte?
      what does condition the "gen" may plus other indicators

      !mi(size): what means?

      Comment


      • #4
        hello teacher
        because my Stata is not familiar
        When I use your code to reform next SAS code
        /////Sas////////////////////
        PROC RANK DATA=rout1 TIES=MEAN PERCENT OUT=rout2;
        VAR bp;
        RANKS vp;
        BY yymm;
        RUN;
        //////my stata///////////
        bysort yymm: egen double median2 = pctile(bp)
        generate byte vp = bp >= median if !mi(bp)

        Stata creates a number of zero
        why ?
        Attached Files

        Comment


        • #5
          You seem to be changing your goalposts. In your original post, the one to which I was responding, your SAS code is
          Code:
          PROC RANK DATA=stock GROUPS=2 OUT=rout1;
          VAR size;
          RANKS sr;
          BY yymm;
          RUN;
          and in your latest post (#4), it's changed to
          Code:
          PROC RANK DATA=rout1 TIES=MEAN PERCENT OUT=rout2;
          VAR bp;
          RANKS vp;
          BY yymm;
          RUN;
          which does something completely different.

          What is it that you want to do?

          Also, you might want to attach your dataset to a post (click on that clipboard-looking icon at the upper right corner of the posting interface) so that the forum participants can see what it is that you're working with.

          Comment


          • #6
            thanks, teacher
            the two SAS code is Fama 3 factor
            step1 divide two group size and bp to generate SMB HML

            SAS Code:
            PROC RANK DATA=stock GROUPS=2 OUT=rout1;
            VAR size;
            RANKS sr;
            BY yymm;
            RUN;
            PROC RANK DATA=rout1 TIES=MEAN PERCENT OUT=rout2;
            VAR bp;
            RANKS vp;
            BY yymm;
            RUN;

            DATA rout2;
            SET rout2;
            vr=1;
            IF vp<=30 THEN vr=0;
            IF vp>=70 THEN vr=2;
            RUN;
            PROC SORT DATA=rout2;
            BY yymm vr sr;
            RUN;
            PROC MEANS DATA=rout2 noprint;
            WEIGHT size;
            VAR ret;
            BY yymm vr sr;
            OUTPUT OUT=mm MEAN=mret;
            run;

            Last edited by Curtis Chou; 01 Jul 2020, 05:56.

            Comment

            Working...
            X