Announcement

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

  • SAS, STATA find centered values for Gravity Model Estimation Code

    -2 down vote favorite

    I am having trouble with something. I have a dataset with years exporters importers and commodity codes. In order to make a panel in STATA and regress I created with the command "egen" a variable i which creates a group of importer exporter and commodity code.
    Code: "egen i = group(exporter importer commodity_code)" I successfully created a panel set with i and year, generated the logarithmic forms of my variables and regressed getting great estimations. So, I have my current dataset (with the logs and the i etc) and I need to find the centered (mean) values of each group. I can do it in SAS, as I create a second dataset with the centered values and then merge it with the original to have the centered values inside along with the real ones. How can I do this in STATA?

    Here is the code from SAS: (Datafors is the dataset's name I import in SAS)

    data Sas1; retain exporter importer COMMODIT year; set Datafors; proc sort; by exporter importer COMMODIT; run; proc means data=Sas1 noprint; var IGDP IGDPCAP ICPI ; OUTPUT OUT=sas3 mean=IGDP IGDPCAP ICPI ; by exporter importer COMMODIT;id I; run; data sas3; set sas3; drop _TYPE_ _FREQ_; run; data sas4; set sas2 sas3; proc sort; by exporter importer commodit year; run; I want the means so when I will re-estimate I will get the predicted ones.
    Thanks in advance




  • #2
    Welcome to the Stata Forum / Statalist.

    I don't work with SAS but, f I understood your query correctly, this information can be found in several sources such as threads from this Forum, the Stata Manual, etc.

    Below, a couple of examples:

    For "grand mean centering":

    Code:
    summarize myvar
    gen myvar_cen1 = myvar – r(mean)
    For "group mean centering":

    Code:
    egen mygroupmean = mean(myvar), by(mygroup)
    gen myvar_cen2 = myvar - mygroupmean
    Hopefully that helps.
    Best regards,

    Marcos

    Comment


    • #3
      The otherwise puzzling start

      -2 down vote favorite

      can be explained by the fact that this is an unedited copy and paste of a question closed on Stack Overflow.

      https://stackoverflow.com/questions/...stimation-code

      Comment


      • #4
        Yes the message from stack overflow was that it was not relevant or something so I posted here where I believe it is. This question was posted from me on Stack Overflow and was not considered proper. However, nobody so far (except of the comment here) has ever solved it. I just want to find an answer for my question nothing more nothing less. Marcos thank you so much I will try everything I can.

        Comment


        • #5
          My point was just small, to explain what would otherwise have seemed mysterious.

          I have never used SAS so don't feel obliged to try to translate. Your question is fine in principle for Statalist but in a discussion forum -- unlike on a helpline -- no one is obliged to answer anything. You might get more attention with formatted SAS code, as here. Sorry if I mess this up.

          Code:
          data Sas1;
          retain exporter importer COMMODIT year;
          set Datafors;
          proc sort;
          by exporter importer COMMODIT;
          run;  
          proc means data=Sas1  noprint;
          var  IGDP IGDPCAP ICPI   ;
          OUTPUT OUT=sas3 mean=IGDP IGDPCAP ICPI    ;
          by exporter importer COMMODIT;id I;
          run;  
          
          data sas3; set sas3;
          drop _TYPE_ _FREQ_;
          run;  
          
          data sas4;
          set sas2 sas3;
          proc sort;
          by exporter importer commodit year;
          run;
          Last edited by Nick Cox; 31 Oct 2018, 07:17.

          Comment

          Working...
          X