Quantcast
Channel: Statalist
Viewing all 73189 articles
Browse latest View live

spmap multiple point groups and legend labels

$
0
0
I have two shapefiles with centroids.
I want to add those points to a map drawn with spmap.
I want that the points in one shapefile are circles and the points in the other shapefile are triangle. The code I'm writting is:

Code:

spmap prod_mean using coCo3.dta, id(id) ///
                    polygon(data("coCo3.dta")) ///
                    saving(v_PAPA, replace)  ///
                    point(data("coCo_PAPA.dta") xcoord(_X)ycoord(_Y) fcolor(emerald) size(small) leglabel("productores"))
This code works good, except that the label of the points does not appear in the legend box.


To add the other centroids I have tried:

Code:

spmap prod_mean using coCo3.dta, id(id) ///
                    polygon(data("coCo3.dta") fcolor(none) ocolor(gray) osize(vvthin)) ///
                    saving(v_PAPA, replace)) ///
                    point(data("coCo_PAPA.dta") xcoord(_X)ycoord(_Y) fcolor(emerald) size(small) leglabel("productores")) ///
                    point(data("coCo_consumidor.dta") xcoord(_X)ycoord(_Y) fcolor(blue) shape(triangle) size(small) legtitle("consumidores"))
I have not found the answer to this in the tutorials nor in the forums.

Thanks in advance.

Running Stata on ARM Systems (using Xenial_Mate)

$
0
0
Hi Statalisters:
Is the Stata 15 Linux version capable to run on ARM SBCs (using Debian or Xenial Mate as distros)?
Thanks in avance.

Announcing improved table1_mc: Stata module to create "Table 1.docx" of baseline characteristics for a manuscript

$
0
0
Dear Statalisters,

I have just posted an updated version of my program table1_mc on SSC. To make use of the ability to put the output into a docx file, version 15.1 is required, otherwise version 14.2.

. sysuse auto, clear
. generate much_headroom = (headroom>3)
. table1_mc, by(foreign) vars(price conts \ weight contn %5.0f \ rep78 cate \ much_headroom bin) nospace clear
. table1_mc_dta2docx using "C:\example Table 1.docx", replace tablenumber("Table 1.") tabletitle("Car characteristics by car type.") footnote("Foreign cars included Audi, Datsun, Toyota and VW cars.")
Array


PS. First announcement was in May 2017 https://www.statalist.org/forums/for...r-a-manuscript

-psmatch2- graph for propensity score distribution before and after matching using the Kernel matching

$
0
0
Hi,

I am trying to estimate a difference-in-difference model combined with a matching estimator using Kernel matching method. I am using -psmatch2- command to estimate the propensity score and using Kernel matching to match my treated and non-treated observations.

But, I need to graph the propensity score distributions of treated versus non-treated observations before and after matching to check that my matching is working. Graphs should be something like attached picture.

I am wondering how I can graph the distribution of propensity score for both treated and non-treated observations before and after matching using Kernel matching method?

The picture is copied from the following webpage: https://www.ncbi.nlm.nih.gov/pmc/articles/PMC4213057/

time-varying covariate

$
0
0
Dear

I would like to know how I can obtain a variable for the case of Smoking that summarizes if in the 4 waves of study that I have, a person never smoked, smoked but stopped, or continues smoking. This is to see the effect that smoking has on mortality

I send a base already in Stset format and split. The codes of the base are the following

Folio_n = id
status_sobrevivencia = death (1 == death)
Smoking2004 = 0 does not smoke, 1 if smokes
Smoking2006 = 0 does not smoke, 1 if smokes,. does not answer)
Smoking2009 = 0 does not smoke, 1 if smokes,. does not answer)
Smoking2015 = 0 does not smoke, 1 if smokes,. does not answer)
Ageband is the age
exposure is the difference between -t -t0
and the corresponding indicators of st -t, origin, -d, -t0


The data is in person-year format. Therefore, each data corresponds to a year in which he remained in the study

Any help with a routine or command that allows me to see if the person still does not smoke, continues smoking or quit smoking, I will thank them very much

regards


copy starting from the next line -----------------------
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input double folio_n float(smoking_dic2004 smoking_dic2006 smoking_dic2009 smoking_dic2015)    double    status_sobrevivencia    byte(_st    _d)    int    _origin    double(_t    _t0)    int    ageband    float    exposure
1775345534 0 0 0 0 . 1 0   865                 43   42.7250341997264 42  .2749658
1775345534 0 0 0 0 . 1 0   865                 44                 43 43         1
1775345534 0 0 0 0 . 1 0   865                 45                 44 44         1
1775345534 0 0 0 0 . 1 0   865                 46                 45 45         1
1775345534 0 0 0 0 . 1 0   865                 47                 46 46         1
1775345534 0 0 0 0 . 1 0   865                 48                 47 47         1
1775345534 0 0 0 0 . 1 0   865                 49                 48 48         1
1775345534 0 0 0 0 . 1 0   865                 50                 49 49         1
1775345534 0 0 0 0 . 1 0   865                 51                 50 50         1
1775345534 0 0 0 0 . 1 0   865                 52                 51 51         1
1775345534 0 0 0 0 . 1 0   865                 53                 52 52         1
1775345534 0 0 0 0 . 1 0   865                 54                 53 53         1
1775345534 0 0 0 0 0 1 0   865    54.593707250342                 54 54 .59370726
1775346031 0 0 0 0 . 1 0   804                 43  42.89192886456908 42 .10807113
1775346031 0 0 0 0 . 1 0   804                 44                 43 43         1
1775346031 0 0 0 0 . 1 0   804                 45                 44 44         1
1775346031 0 0 0 0 . 1 0   804                 46                 45 45         1
1775346031 0 0 0 0 . 1 0   804                 47                 46 46         1
1775346031 0 0 0 0 . 1 0   804                 48                 47 47         1
1775346031 0 0 0 0 . 1 0   804                 49                 48 48         1
1775346031 0 0 0 0 . 1 0   804                 50                 49 49         1
1775346031 0 0 0 0 . 1 0   804                 51                 50 50         1
1775346031 0 0 0 0 . 1 0   804                 52                 51 51         1
1775346031 0 0 0 0 . 1 0   804                 53                 52 52         1
1775346031 0 0 0 0 . 1 0   804                 54                 53 53         1
1775346031 0 0 0 0 0 1 0   804  54.76060191518468                 54 54  .7606019
1775346244 1 1 1 1 . 1 0  1719                 41 40.388508891928865 40  .6114911
1775346244 1 1 1 1 . 1 0  1719                 42                 41 41         1
1775346244 1 1 1 1 . 1 0  1719                 43                 42 42         1
1775346244 1 1 1 1 . 1 0  1719                 44                 43 43         1
1775346244 1 1 1 1 . 1 0  1719                 45                 44 44         1
1775346244 1 1 1 1 . 1 0  1719                 46                 45 45         1
1775346244 1 1 1 1 . 1 0  1719                 47                 46 46         1
1775346244 1 1 1 1 . 1 0  1719                 48                 47 47         1
1775346244 1 1 1 1 . 1 0  1719                 49                 48 48         1
1775346244 1 1 1 1 . 1 0  1719                 50                 49 49         1
1775346244 1 1 1 1 . 1 0  1719                 51                 50 50         1
1775346244 1 1 1 1 . 1 0  1719                 52                 51 51         1
1775346244 1 1 1 1 0 1 0  1719  52.25718194254446                 52 52 .25718194
1775346457 0 0 0 0 . 1 0  1141                 42  41.96990424076608 41 .03009576
1775346457 0 0 0 0 . 1 0  1141                 43                 42 42         1
1775346457 0 0 0 0 . 1 0  1141                 44                 43 43         1
1775346457 0 0 0 0 . 1 0  1141                 45                 44 44         1
1775346457 0 0 0 0 . 1 0  1141                 46                 45 45         1
1775346457 0 0 0 0 . 1 0  1141                 47                 46 46         1
1775346457 0 0 0 0 . 1 0  1141                 48                 47 47         1
1775346457 0 0 0 0 . 1 0  1141                 49                 48 48         1
1775346457 0 0 0 0 . 1 0  1141                 50                 49 49         1
1775346457 0 0 0 0 . 1 0  1141                 51                 50 50         1
1775346457 0 0 0 0 . 1 0  1141                 52                 51 51         1
1775346457 0 0 0 0 . 1 0  1141                 53                 52 52         1
1775346457 0 0 0 0 0 1 0  1141  53.83857729138167                 53 53  .8385773
1775346528 1 1 0 . . 1 0   835                 43  42.80711354309165 42 .19288646
1775346528 1 1 0 . . 1 0   835                 44                 43 43         1
1775346528 1 1 0 . . 1 0   835                 45                 44 44         1
1775346528 1 1 0 . . 1 0   835                 46                 45 45         1
1775346528 1 1 0 . . 1 0   835                 47                 46 46         1
1775346528 1 1 0 . . 1 0   835                 48                 47 47         1
1775346528 1 1 0 . . 1 0   835                 49                 48 48         1
1775346528 1 1 0 . . 1 0   835                 50                 49 49         1
1775346528 1 1 0 . . 1 0   835                 51                 50 50         1
1775346528 1 1 0 . . 1 0   835                 52                 51 51         1
1775346528 1 1 0 . . 1 0   835                 53                 52 52         1
1775346528 1 1 0 . . 1 0   835                 54                 53 53         1
1775346528 1 1 0 . 0 1 0   835  54.67578659370725                 54 54  .6757866
1775346883 0 0 . . . 1 0 -1965                 51 50.467852257181946 50 .53214777
1775346883 0 0 . . . 1 0 -1965                 52                 51 51         1
1775346883 0 0 . . 1 1 1 -1965  52.62927496580027                 52 52   .629275
1775347025 1 1 0 1 . 1 0   835                 43  42.80711354309165 42 .19288646
1775347025 1 1 0 1 . 1 0   835                 44                 43 43         1
1775347025 1 1 0 1 . 1 0   835                 45                 44 44         1
1775347025 1 1 0 1 . 1 0   835                 46                 45 45         1
1775347025 1 1 0 1 . 1 0   835                 47                 46 46         1
1775347025 1 1 0 1 . 1 0   835                 48                 47 47         1
1775347025 1 1 0 1 . 1 0   835                 49                 48 48         1
1775347025 1 1 0 1 . 1 0   835                 50                 49 49         1
1775347025 1 1 0 1 . 1 0   835                 51                 50 50         1
1775347025 1 1 0 1 . 1 0   835                 52                 51 51         1
1775347025 1 1 0 1 . 1 0   835                 53                 52 52         1
1775347025 1 1 0 1 . 1 0   835                 54                 53 53         1
1775347025 1 1 0 1 0 1 0   835  54.67578659370725                 54 54  .6757866
1775347167 1 0 1 1 . 1 0  1169                 42  41.89329685362517 41 .10670315
1775347167 1 0 1 1 . 1 0  1169                 43                 42 42         1
1775347167 1 0 1 1 . 1 0  1169                 44                 43 43         1
1775347167 1 0 1 1 . 1 0  1169                 45                 44 44         1
1775347167 1 0 1 1 . 1 0  1169                 46                 45 45         1
1775347167 1 0 1 1 . 1 0  1169                 47                 46 46         1
1775347167 1 0 1 1 . 1 0  1169                 48                 47 47         1
1775347167 1 0 1 1 . 1 0  1169                 49                 48 48         1
1775347167 1 0 1 1 . 1 0  1169                 50                 49 49         1
1775347167 1 0 1 1 . 1 0  1169                 51                 50 50         1
1775347167 1 0 1 1 . 1 0  1169                 52                 51 51         1
1775347167 1 0 1 1 . 1 0  1169                 53                 52 52         1
1775347167 1 0 1 1 0 1 0  1169 53.761969904240765                 53 53  .7619699
1775347664 1 0 1 . . 1 0  1200                 42 41.808481532147745 41 .19151847
1775347664 1 0 1 . . 1 0  1200                 43                 42 42         1
1775347664 1 0 1 . . 1 0  1200                 44                 43 43         1
1775347664 1 0 1 . . 1 0  1200                 45                 44 44         1
1775347664 1 0 1 . . 1 0  1200                 46                 45 45         1
1775347664 1 0 1 . . 1 0  1200                 47                 46 46         1
end
copy up to and including the previous line ------------------

Listed 100 out of 119722 observations
Use the count() option to list more

Ask for resources

$
0
0
Hi All,

I want to address a research question for which I have the data, but I don’t know exactly how I should approach the data and what methods I should use. I really appreciate it if you could point me to the right resources and methods.

Here is my data: I have daily observations of team engagement and monthly observations of team performance for about 2000 teams over 2 years. There are different numbers of observations for different teams, because teams were formed at different starting points and some of them were dissolved over time. Everyday it’s possible that someone joins the team or leaves the team, or both events happen.
I want to study how each of these events can influence team engagement, how changes on team engagement unfold over time and how these fluctuations influence team performance over time.

Is it possible to address these questions in Stata, what method should I use and are there books or other resources that I can use?


Thank you very much

Regression for each industry in each year in the sample

$
0
0
Dear All,

I am using Stata for my Master thesis. My study sample covers 15 years. There are 12 industry in the sample as well.

I have tried many times to use a Stata command that allows me to to run the OLS regression for each industry and year in my data set. I will really appreciate your support on doing this.

Thank you

passing mata function arguments by value so they are not modified within the function

$
0
0
I am having problems with a real scalar argument being passed to a Mata function having its value changed by the calling code. In programming terms I would like to pass the argument by value, but instead it is being passed by reference. It is obvious how to do the reverse (pass the pointer and then de-reference it within the called function), but I am stuck with how to pass the value only (i.e perform a bitwise copy to a new memory address). The example and output proving the passed scalar is being modified is included below. Thanks for your help.

Code:
class searchArgs {
    public real scalar x,n,p
    public void toString()
}

void searchArgs::toString(){
    printf("x:%f,n:%f,p:%f",this.x,this.n,this.p);
}

real scalar BinarySearch(
    real scalar target,
    real scalar min,
    real scalar max,
    class searchArgs scalar sa,
    pointer(real scalar function) delegate,
    | real scalar approx,
    real scalar maxIts)
{
    real scalar k, val, argLen;
    argLen = args();
    if (argLen<6){
        approx = 0.0005;
    }
    if (argLen < 7){
        maxIts = 200;
    }
    for(k=0;k<maxIts;k++){
        sa.x = (min+max)/2;
        val = (*delegate)(sa);
        //debug tool - remove later
        sa.toString();
        if (val >= .) {
          return(.);
        }
        if ((abs(val-target)<=approx)){
          return(sa.x)
        }
        if (val<target) {
          min = sa.x;
        } else {
          max = sa.x;
        }
    }
    return(.);
}

real scalar LbBeta(class searchArgs sa){
    return(ibetatail(sa.x+1,sa.n-sa.x, sa.p))
}

real scalar UbBeta(class searchArgs sa){
    return(1-ibetatail(sa.x,sa.n-sa.x+1, sa.p))
}
when calling the binary search algorithm with
Code:
sa = searchArgs()
sa.n=242
sa.p=0.0414434
BinarySearch(0.02275, 0, sa.n, sa, &LbBeta())
the output looks like
Code:
x:121,n:242,p:.0414434  1
x:60.5,n:121,p:.0414434  1
x:30.25,n:60.5,p:.0414434  1
x:15.125,n:30.25,p:.0414434  1
Note that the value of sa.n is the value of sa.x in the previous iteration - that is "max = sa.x" is also assigning the value to sa.n, because that is the value passed as the max argument.

Obviously I can get the function to give me the desired value by calling "BinarySearch(0.02275, 0, 242, sa, &LbBeta())", but generally I would like the scalar arguments passed to a function to remain untouched.

Kolmogorov-Smirnov test

$
0
0
Hi all, another question. The previous advice has been so helpful! I ran an experiment on risk preferences: people make 10 decisions. Each decision is between two options (a safe option and a risky option), coded as 1 and 0 respectively. Additionally I ran an experiment on rolling a standard six sided die (it measures honesty).

Half the subjects completed both experiments in a control group. The other half completed the same experiments under slightly different conditions (treatment group). I have plotted both of them and found that the treatment makes no difference. Although I need a p-value to show this.

I have decided to use the Kolmogorov-Smirnov test.

Thus my command is: ksmirnov totalsafe, by(treatment)

totalsafe here being the number of safe choices in the risk-preferences experiment as explained above.

I have seen that in the past has recommended against the KS test. I have 2 questions here:

1) Is the above command find to satisfy the need for a p-value? (I am using it because the previous literature seems to use it)
2) Are there any other tests that you would recommend?

Thanks again, the help has been amazing!

testing spam filter

Experimental Design and Synthetic Cohort Methods

$
0
0
I have a problem that I have not seen in the literature or discussed online. I am trying to design an experiment where there will be very few treated geographic units, perhaps only one. You can think of these as states of the US for the purpose of this question. In the non-experimental setting, synthetic cohort methods (like -synth- and -synth_runner- and -npsynth-) have been used to create Frankenstein control group(s) for causal inference. My situation is different since I can choose the treated unit(s). In doing that, there are several challenges that I am facing:
  1. Is the SC method still the best way to approach this question?
  2. How to do power calculation via simulation, when the SC estimation takes a considerable amount of time (especially with the nested optimization option, many covariates and half dozen outcomes)?
  3. What criteria should be used to select the treated unit? Good RMSE between the treated and their SC on historical data? Lack of significant false positives in false placebo tests, when you vary the timing of the test?
  4. When an additional unit gets assigned to treatment, it is pulled out from the set of potential donors, which alters how well the method works for the other treated units if that unit was heavily weighted and there is no suitable substitute.
  5. If there are reasons to worry about spillovers between treated and control units, is there a way to make the selection process deal with this? In doing ordinary SC, I would often exclude nearby units from the set of potential donors.
Any advice of any of these points would be greatly appreciated.

putdocx etable dropping multiple rows/columns

$
0
0
Is there a way to specify multiple rows and/or columns to drop for an etable in a single command? Currently I have:
putdocx clear
putdocx begin
putdocx table test = etable
putdocx table test(.,5), drop
putdocx table test(.,4), drop
putdocx table test(.,3), drop
putdocx table test(14,.), drop
putdocx table test(11,.), drop
putdocx table test(8,.), drop
putdocx table test(5,.), drop
putdocx table test(2,.), drop
putdocx save myresults.docx, replace

What has not worked: test(.,5,4,3) or test(.,5 4 3)

Thanks

cubic B-spline for Call options

$
0
0
Hi,

I have a time series database of Call options so on each day I have option price of different moneyness for example for january 1, 2015 i have the following data
date moneyness call price
01/01/15 0,960736871 0,1
01/01/15 0,969238937 0,24
01/01/15 0,977892876 0,58
01/01/15 0,986702681 1,22
01/01/15 0,995672703 2,24
01/01/15 1,004807353 3,6
01/01/15 1,014111161 5,35
01/01/15 1,023588777 7,55
01/01/15 1,033245325 9,6
01/01/15 1,043085694 11,95
01/01/15 1,053115368 14,4
01/01/15 1,063339829 17
01/01/15 1,073764682 19,25
01/01/15 1,084396005 21,95
my purpose is to interpolate Call prices for only 3 values of moneyness (0.97 ; 1 ; 1.06)
to do so I have use the following stata code :

rename moneyness x
rename call_price y
mata
X = st_data(. ,"x")
Y = st_data(. ,"y")
XX = st_data(.,"xx")
A = spline3(X,Y)
B = spline3eval(A,XX)
yy=st_addvar("float", "yy")
st_store(. ,yy,B)
end
browse

and i get this :
date moneyness call price xx yy
01/01/15 0,960736871 0,1 0,970000029 0,260024935
01/01/15 0,969238937 0,24 1 2,846917629
01/01/15 0,977892876 0,58 1,059999943 16,18859863
01/01/15 0,986702681 1,22
01/01/15 0,995672703 2,24
01/01/15 1,004807353 3,6
01/01/15 1,014111161 5,35
01/01/15 1,023588777 7,55
01/01/15 1,033245325 9,6
01/01/15 1,043085694 11,95
01/01/15 1,053115368 14,4
01/01/15 1,063339829 17
01/01/15 1,073764682 19,25
01/01/15 1,084396005 21,95
Now I want to do the same thing but with data in different dates so for each date(january 1, 2015 and january 2, 2015 for example) I want to apply the spline code and get 3 prices for each moneyness value but I dont know how to do it...
date moneyness call price xx yy
01/01/15 0,960736871 0,1 0,970000029 0,260024935
01/01/15 0,969238937 0,24 1 2,846917629
01/01/15 0,977892876 0,58 1,059999943 16,18859863
01/01/15 0,986702681 1,22
01/01/15 0,995672703 2,24
01/01/15 1,004807353 3,6
01/01/15 1,014111161 5,35
01/01/15 1,023588777 7,55
01/01/15 1,033245325 9,6
01/01/15 1,043085694 11,95
01/01/15 1,053115368 14,4
01/01/15 1,063339829 17
01/01/15 1,073764682 19,25
01/01/15 1,084396005 21,95
02/01/15 0,952399979 24,15 0,97 ?
02/01/15 0,976302977 26,5 1 ?
02/01/15 1,017591858 28,8 1,06 ?
02/01/15 1,079113436 31,5
02/01/15 1,140874982 34,15
02/01/15 1,152884245 35,9
02/01/15 1,165148973 39,5
02/01/15 1,177677393 41,65
02/01/15 1,190478206 44,25
02/01/15 1,203560472 45,9
02/01/15 1,21693337 48,8
Thank you very much for any help!

Best regards,
Emna


How to generate 2 new variables consisting of the upper and lower confidence intervals of another variable

$
0
0
Hello everyone,
I have an issue regarding creating two new variables consisting of the upper and lower confidence intervals of another variable. I would also like to combine two bar graphs into one. Thank you in advance for your help.

Test

$
0
0

Code:
Probit model for atrisk_only
-------- True --------
Classified | D ~D | Total
-----------+--------------------------+-----------
+ | 1 1 | 2
- | 245 2474 | 2719
-----------+--------------------------+-----------
Total | 246 2475 | 2721

Classified + if predicted Pr(D) >= .5
True D defined as atrisk_only != 0
--------------------------------------------------
Sensitivity Pr( +| D) 0.41%
Specificity Pr( -|~D) 99.96%
Positive predictive value Pr( D| +) 50.00%
Negative predictive value Pr(~D| -) 90.99%
--------------------------------------------------
False + rate for true ~D Pr( +|~D) 0.04%
False - rate for true D Pr( -| D) 99.59%
False + rate for classified + Pr(~D| +) 50.00%
False - rate for classified - Pr( D| -) 9.01%
--------------------------------------------------
Correctly classified 90.96

Saving results from two-way tabulation with summary

$
0
0
I'm trying to run a two-way tabulation using the summarize() option. Example:
Code:
sysuse auto
generate wgtcat = autocode(weight,4,1760,4840)
tabulate wgtcat foreign, summarize(mpg)
The issue I have is that I can't figure out any way to save the results.
Code:
 return list
shows that nothing is saved. Is there anything I can do to save the results? I'd like to use them in a graph or in some other way manipulate them, but it seems like I've hit a dead end.

Percent correctly predicted in probit estimation

$
0
0
Dear statalisters,
I checked my probit model by applying the percent correctly predicted method for its goodness-of-fit by using the following commands:

Code:
qui probit atrisk_only age_mth female javanese wi1 muslim i.region logfoodconpc year14 lognonfoodexppc percentagefruits percstarch smallhh bmi_fa2 bmi_mo secondary_fa  underweight_fa if age_mth>=24, cl(cl_id)
estat class, cutoff(0.5)
Here is my stata-output:

Code:
Probit model for atrisk_only
-------- True --------
Classified | D ~D | Total
-----------+--------------------------+-----------
+ | 1 1 | 2
- | 245 2474 | 2719
-----------+--------------------------+-----------
Total | 246 2475 | 2721

Classified + if predicted Pr(D) >= .5
True D defined as atrisk_only != 0
--------------------------------------------------
Sensitivity Pr( +| D) 0.41%
Specificity Pr( -|~D) 99.96%
Positive predictive value Pr( D| +) 50.00%
Negative predictive value Pr(~D| -) 90.99%
--------------------------------------------------
False + rate for true ~D Pr( +|~D) 0.04%
False - rate for true D Pr( -| D) 99.59%
False + rate for classified + Pr(~D| +) 50.00%
False - rate for classified - Pr( D| -) 9.01%
--------------------------------------------------
Correctly classified 90.96%
It seems that my model is good in predicting when y=0 (what is not a surprise, since in most cases of my sample y=0), but fails to predict when y=1.
Is it correct to take this as a sign that my model does not have a good fit? What could I do to improve my model? Are there other goodness-of-fit measures that might be more suitable for my case?

Thank you in advance!
Best Jan

Why does sureg with constraints deliver results different from reg?

$
0
0
I have different outcomes and regress them on the same set of variables. My understanding of seemingly unrelated regression (with constraints) was that I could replicate the result by expanding my dataset and using interactions in OLS.

For example:
Code:
sysuse auto, clear
set seed 123
keep mpg rep78 price make

// The outcomes are mpg1 and mpg2
rename mpg mpg1
gen mpg2 = mpg1+rnormal()

// -sureg-
// Only allow the coefficient on price to differ and run sureg
constraint 1 [mpg1]rep78 = [mpg2]rep78
constraint 2 [mpg1]_cons = [mpg2]_cons
sureg (mpg1 price rep78) (mpg2 price rep78), const(1 2)

// -reg-
// Reshape the data and interact price with group.
// The value of group tell us whether mpg is equal to mpg1 or mpg2
qui reshape long mpg, i(make) j(group)
reg mpg i.group#c.price rep78, cluster(make)
The coefficients of the routines are very similar, but not exactly the same. Why is that? I thought that the routines would boil down to the same calculation, whether using -reg- or -sureg-.
Also standard errors, clustered on the level of observation (make) before the reshape, are larger than the ones from -sureg-. This orderings is maintained when running a seemingly unrelated regression with robust standard errors, using -mysureg- from http://www.stata-press.com/data/ml4.html

This is the output of -sureg-:
Code:
Seemingly unrelated regression
--------------------------------------------------------------------------
Equation             Obs   Parms        RMSE    "R-sq"       chi2        P
--------------------------------------------------------------------------
mpg1                  69       2    4.615597    0.3719      39.30   0.0000
mpg2                  69       2    4.891128    0.3687      39.37   0.0000
--------------------------------------------------------------------------

 ( 1)  [mpg1]rep78 - [mpg2]rep78 = 0
 ( 2)  [mpg1]_cons - [mpg2]_cons = 0
------------------------------------------------------------------------------
             |      Coef.   Std. Err.      z    P>|z|     [95% Conf. Interval]
-------------+----------------------------------------------------------------
mpg1         |
       price |  -.0009026   .0001907    -4.73   0.000    -.0012764   -.0005287
       rep78 |   2.320978   .5602128     4.14   0.000     1.222981    3.418974
       _cons |   18.90376   2.298645     8.22   0.000      14.3985    23.40903
-------------+----------------------------------------------------------------
mpg2         |
       price |  -.0009137   .0001928    -4.74   0.000    -.0012916   -.0005358
       rep78 |   2.320978   .5602128     4.14   0.000     1.222981    3.418974
       _cons |   18.90376   2.298645     8.22   0.000      14.3985    23.40903
------------------------------------------------------------------------------
and this of -reg-:

Code:
Linear regression                               Number of obs     =        138
                                                F(3, 68)          =       9.68
                                                Prob > F          =     0.0000
                                                R-squared         =     0.3713
                                                Root MSE          =     4.8217

                                   (Std. Err. adjusted for 69 clusters in make)
-------------------------------------------------------------------------------
              |               Robust
          mpg |      Coef.   Std. Err.      t    P>|t|     [95% Conf. Interval]
--------------+----------------------------------------------------------------
group#c.price |
           1  |  -.0009423   .0002145    -4.39   0.000    -.0013704   -.0005142
           2  |  -.0009534   .0002132    -4.47   0.000    -.0013788    -.000528
              |
        rep78 |   2.473056   .7210859     3.43   0.001     1.034152    3.911961
        _cons |   18.68333   2.416886     7.73   0.000     13.86051    23.50615
-------------------------------------------------------------------------------
If someone could help me understand the differences between the two or point me to somewhere, I'd be glad.

Lord's paradox also applies to different measures?

$
0
0
Hi all,

I am working with a mini-panel and am trying to examine how liberties at job entry affects the later job satisfaction. I have information on job satisfaction at job entry (sweep 1) and after three years (sweep 3). For sweep 2 there is no information on job satisfaction and the measures of sweep 1 and 3 differ (different question and different scale points).

I thought I would specify the following model (exemplary)

HTML Code:
reg job satisfaction_s3 i.liberites job satisfaction_s1 controls
Meaning I want to control the job satisfaction at job entry in these models as well. I have read however that this is problematic (Lord's paradox). However, all I found thematized this problem when measures are identical at different time points.

My only question now is: does this problem also apply when my two measures differ (different question and scale points), because here, too groups could have different starting points, or is this problem then irrelevant for me?

Cheers,

Evelyn

Problems with SIEVE EGENMORE

$
0
0
I am using egenmore to clean my database, I have used the same code previously and all was well until today when my egenmore sieve fonction stopped working. It says that it has a syntax error. Can someone tell me what is going wrong, why doesn't my code that I have used previously not work today !. This is the Trace On that I get:
egen nn_fatot=sieve(mhab), char(0 1 2 3 4 5 6 7 8 9 . )
--------------------------------------------------------------------------------------------------------------------------------------------- begin egen ---
- version 6, missing
- local cvers = _caller()
- gettoken type 0 : 0, parse(" =(")
- gettoken name 0 : 0, parse(" =(")
- if `"`name'"'=="=" {
= if `"="'=="=" {
- local name `"`type'"'
= local name `"nn_fatot"'
- local type : set type
- }
- else {
gettoken eqsign 0 : 0, parse(" =(")
if `"`eqsign'"' != "=" {
error 198
}
}
- confirm new variable `name'
= confirm new variable nn_fatot
- gettoken fcn 0 : 0, parse(" =(")
- gettoken args 0 : 0, parse(" ,") match(par)
- if "`c(adoarchive)'"=="1" {
= if ""=="1" {
capture qui _stfilearchive find _g`fcn'.ado
if _rc {
di as error "unknown egen function `fcn'()"
exit 133
}
}
- else {
- capture qui findfile _g`fcn'.ado
= capture qui findfile _gsieve.ado
--------------------------------------------------------------------------------------------------------------------------------------- begin findfile ---
- version 8
- gettoken fn 0 : 0, parse(" ,")
- syntax [, ALL noDEScend PATH(string)]
- if `"`path'"'=="" {
= if `""'=="" {
- local path `"`c(adopath)'"'
= local path `"BASE;SITE;.;PERSONAL;PLUS;OLDPLACE"'
- }
- local n 0
- local subdir : adosubdir `"`fn'"'
= local subdir : adosubdir `"_gsieve.ado"'
- if `"`subdir'"' != "" {
= if `"_"' != "" {
- gettoken d path : path, parse(";")
- while `"`d'"'!="" {
= while `"BASE"'!="" {
- if `"`d'"' != ";" {
= if `"BASE"' != ";" {
- local d : sysdir `"`d'"'
= local d : sysdir `"BASE"'
- local ffn `"`d'`fn'"'
= local ffn `"C:\Program Files (x86)\Stata13\ado\base/_gsieve.ado"'
- capture confirm file `"`ffn'"'
= capture confirm file `"C:\Program Files (x86)\Stata13\ado\base/_gsieve.ado"'
- if _rc==0 {
di as txt `"`ffn'"'
if "`all'"=="" {
ret local fn `"`ffn'"'
exit
}
if `n' {
ret local fn `"`return(fn)' "`ffn'""'
}
else ret local fn `""`ffn'""'
local n 1
}
- if "`descend'"=="" {
= if ""=="" {
- local ffn `"`d'`subdir'`c(dirsep)'`fn'"'
= local ffn `"C:\Program Files (x86)\Stata13\ado\base/_/_gsieve.ado"'
- capture confirm file `"`ffn'"'
= capture confirm file `"C:\Program Files (x86)\Stata13\ado\base/_/_gsieve.ado"'
- if _rc==0 {
di as txt `"`ffn'"'
if "`all'"=="" {
ret local fn `"`ffn'"'
exit
}
if `n' {
ret local fn `"`return(fn)' "`ffn'""'
}
else ret local fn `"`ffn'"'
local n 1
}
- }
- }
- gettoken d path : path, parse(" ;")
- }
- while `"`d'"'!="" {
= while `";"'!="" {
- if `"`d'"' != ";" {
= if `";"' != ";" {
local d : sysdir `"`d'"'
local ffn `"`d'`fn'"'
capture confirm file `"`ffn'"'
if _rc==0 {
di as txt `"`ffn'"'
if "`all'"=="" {
ret local fn `"`ffn'"'
exit
}
if `n' {
ret local fn `"`return(fn)' "`ffn'""'
}
else ret local fn `""`ffn'""'
local n 1
}
if "`descend'"=="" {
local ffn `"`d'`subdir'`c(dirsep)'`fn'"'
capture confirm file `"`ffn'"'
if _rc==0 {
di as txt `"`ffn'"'
if "`all'"=="" {
ret local fn `"`ffn'"'
exit
}
if `n' {
ret local fn `"`return(fn)' "`ffn'""'
}
else ret local fn `"`ffn'"'
local n 1
}
}
}
- gettoken d path : path, parse(" ;")
- }
- while `"`d'"'!="" {
= while `"SITE"'!="" {
- if `"`d'"' != ";" {
= if `"SITE"' != ";" {
- local d : sysdir `"`d'"'
= local d : sysdir `"SITE"'
- local ffn `"`d'`fn'"'
= local ffn `"C:\Program Files (x86)\Stata13\ado\site/_gsieve.ado"'
- capture confirm file `"`ffn'"'
= capture confirm file `"C:\Program Files (x86)\Stata13\ado\site/_gsieve.ado"'
- if _rc==0 {
di as txt `"`ffn'"'
if "`all'"=="" {
ret local fn `"`ffn'"'
exit
}
if `n' {
ret local fn `"`return(fn)' "`ffn'""'
}
else ret local fn `""`ffn'""'
local n 1
}
- if "`descend'"=="" {
= if ""=="" {
- local ffn `"`d'`subdir'`c(dirsep)'`fn'"'
= local ffn `"C:\Program Files (x86)\Stata13\ado\site/_/_gsieve.ado"'
- capture confirm file `"`ffn'"'
= capture confirm file `"C:\Program Files (x86)\Stata13\ado\site/_/_gsieve.ado"'
- if _rc==0 {
di as txt `"`ffn'"'
if "`all'"=="" {
ret local fn `"`ffn'"'
exit
}
if `n' {
ret local fn `"`return(fn)' "`ffn'""'
}
else ret local fn `"`ffn'"'
local n 1
}
- }
- }
- gettoken d path : path, parse(" ;")
- }
- while `"`d'"'!="" {
= while `";"'!="" {
- if `"`d'"' != ";" {
= if `";"' != ";" {
local d : sysdir `"`d'"'
local ffn `"`d'`fn'"'
capture confirm file `"`ffn'"'
if _rc==0 {
di as txt `"`ffn'"'
if "`all'"=="" {
ret local fn `"`ffn'"'
exit
}
if `n' {
ret local fn `"`return(fn)' "`ffn'""'
}
else ret local fn `""`ffn'""'
local n 1
}
if "`descend'"=="" {
local ffn `"`d'`subdir'`c(dirsep)'`fn'"'
capture confirm file `"`ffn'"'
if _rc==0 {
di as txt `"`ffn'"'
if "`all'"=="" {
ret local fn `"`ffn'"'
exit
}
if `n' {
ret local fn `"`return(fn)' "`ffn'""'
}
else ret local fn `"`ffn'"'
local n 1
}
}
}
- gettoken d path : path, parse(" ;")
- }
- while `"`d'"'!="" {
= while `"."'!="" {
- if `"`d'"' != ";" {
= if `"."' != ";" {
- local d : sysdir `"`d'"'
= local d : sysdir `"."'
- local ffn `"`d'`fn'"'
= local ffn `"./_gsieve.ado"'
- capture confirm file `"`ffn'"'
= capture confirm file `"./_gsieve.ado"'
- if _rc==0 {
di as txt `"`ffn'"'
if "`all'"=="" {
ret local fn `"`ffn'"'
exit
}
if `n' {
ret local fn `"`return(fn)' "`ffn'""'
}
else ret local fn `""`ffn'""'
local n 1
}
- if "`descend'"=="" {
= if ""=="" {
- local ffn `"`d'`subdir'`c(dirsep)'`fn'"'
= local ffn `"./_/_gsieve.ado"'
- capture confirm file `"`ffn'"'
= capture confirm file `"./_/_gsieve.ado"'
- if _rc==0 {
di as txt `"`ffn'"'
if "`all'"=="" {
ret local fn `"`ffn'"'
exit
}
if `n' {
ret local fn `"`return(fn)' "`ffn'""'
}
else ret local fn `"`ffn'"'
local n 1
}
- }
- }
- gettoken d path : path, parse(" ;")
- }
- while `"`d'"'!="" {
= while `";"'!="" {
- if `"`d'"' != ";" {
= if `";"' != ";" {
local d : sysdir `"`d'"'
local ffn `"`d'`fn'"'
capture confirm file `"`ffn'"'
if _rc==0 {
di as txt `"`ffn'"'
if "`all'"=="" {
ret local fn `"`ffn'"'
exit
}
if `n' {
ret local fn `"`return(fn)' "`ffn'""'
}
else ret local fn `""`ffn'""'
local n 1
}
if "`descend'"=="" {
local ffn `"`d'`subdir'`c(dirsep)'`fn'"'
capture confirm file `"`ffn'"'
if _rc==0 {
di as txt `"`ffn'"'
if "`all'"=="" {
ret local fn `"`ffn'"'
exit
}
if `n' {
ret local fn `"`return(fn)' "`ffn'""'
}
else ret local fn `"`ffn'"'
local n 1
}
}
}
- gettoken d path : path, parse(" ;")
- }
- while `"`d'"'!="" {
= while `"PERSONAL"'!="" {
- if `"`d'"' != ";" {
= if `"PERSONAL"' != ";" {
- local d : sysdir `"`d'"'
= local d : sysdir `"PERSONAL"'
- local ffn `"`d'`fn'"'
= local ffn `"c:\ado\personal/_gsieve.ado"'
- capture confirm file `"`ffn'"'
= capture confirm file `"c:\ado\personal/_gsieve.ado"'
- if _rc==0 {
di as txt `"`ffn'"'
if "`all'"=="" {
ret local fn `"`ffn'"'
exit
}
if `n' {
ret local fn `"`return(fn)' "`ffn'""'
}
else ret local fn `""`ffn'""'
local n 1
}
- if "`descend'"=="" {
= if ""=="" {
- local ffn `"`d'`subdir'`c(dirsep)'`fn'"'
= local ffn `"c:\ado\personal/_/_gsieve.ado"'
- capture confirm file `"`ffn'"'
= capture confirm file `"c:\ado\personal/_/_gsieve.ado"'
- if _rc==0 {
di as txt `"`ffn'"'
if "`all'"=="" {
ret local fn `"`ffn'"'
exit
}
if `n' {
ret local fn `"`return(fn)' "`ffn'""'
}
else ret local fn `"`ffn'"'
local n 1
}
- }
- }
- gettoken d path : path, parse(" ;")
- }
- while `"`d'"'!="" {
= while `";"'!="" {
- if `"`d'"' != ";" {
= if `";"' != ";" {
local d : sysdir `"`d'"'
local ffn `"`d'`fn'"'
capture confirm file `"`ffn'"'
if _rc==0 {
di as txt `"`ffn'"'
if "`all'"=="" {
ret local fn `"`ffn'"'
exit
}
if `n' {
ret local fn `"`return(fn)' "`ffn'""'
}
else ret local fn `""`ffn'""'
local n 1
}
if "`descend'"=="" {
local ffn `"`d'`subdir'`c(dirsep)'`fn'"'
capture confirm file `"`ffn'"'
if _rc==0 {
di as txt `"`ffn'"'
if "`all'"=="" {
ret local fn `"`ffn'"'
exit
}
if `n' {
ret local fn `"`return(fn)' "`ffn'""'
}
else ret local fn `"`ffn'"'
local n 1
}
}
}
- gettoken d path : path, parse(" ;")
- }
- while `"`d'"'!="" {
= while `"PLUS"'!="" {
- if `"`d'"' != ";" {
= if `"PLUS"' != ";" {
- local d : sysdir `"`d'"'
= local d : sysdir `"PLUS"'
- local ffn `"`d'`fn'"'
= local ffn `"c:\ado\plus/_gsieve.ado"'
- capture confirm file `"`ffn'"'
= capture confirm file `"c:\ado\plus/_gsieve.ado"'
- if _rc==0 {
di as txt `"`ffn'"'
if "`all'"=="" {
ret local fn `"`ffn'"'
exit
}
if `n' {
ret local fn `"`return(fn)' "`ffn'""'
}
else ret local fn `""`ffn'""'
local n 1
}
- if "`descend'"=="" {
= if ""=="" {
- local ffn `"`d'`subdir'`c(dirsep)'`fn'"'
= local ffn `"c:\ado\plus/_/_gsieve.ado"'
- capture confirm file `"`ffn'"'
= capture confirm file `"c:\ado\plus/_/_gsieve.ado"'
- if _rc==0 {
- di as txt `"`ffn'"'
= di as txt `"c:\ado\plus/_/_gsieve.ado"'
- if "`all'"=="" {
= if ""=="" {
- ret local fn `"`ffn'"'
= ret local fn `"c:\ado\plus/_/_gsieve.ado"'
- exit
----------------------------------------------------------------------------------------------------------------------------------------- end findfile ---
- if (`"`r(fn)'"' == "") {
= if (`"c:\ado\plus/_/_gsieve.ado"' == "") {
di as error "unknown egen function `fcn'()"
exit 133
}
- }
- if `"`par'"' != "(" {
= if `"("' != "(" {
exit 198
}
- if `"`args'"' == "_all" | `"`args'"' == "*" {
= if `"mhab"' == "_all" | `"mhab"' == "*" {
version 7.0, missing
unab args : _all
local args : subinstr local args "`_sortindex'" "", all word
version 6.0, missing
}
- syntax [if] [in] [, *]
- if _by() {
local byopt "by(`_byvars')"
local cma ","
}
- else if `"`options'"' != "" {
= else if `"char(0 1 2 3 4 5 6 7 8 9 . )"' != "" {
- local cma ","
- }
- tempvar dummy
- global EGEN_Varname `name'
= global EGEN_Varname nn_fatot
- version 7.0, missing
- global EGEN_SVarname `_sortindex'
= global EGEN_SVarname __000000
- version 6.0, missing
- if ("`fcn'" == "mode" | "`fcn'" == "concat") {
= if ("sieve" == "mode" | "sieve" == "concat") {
local vv : display "version " string(`cvers') ", missing:"
}
- capture noisily `vv' _g`fcn' `type' `dummy' = (`args') `if' `in' `cma' `byopt' `options'
= capture noisily _gsieve float __000001 = (mhab) , char(0 1 2 3 4 5 6 7 8 9 . )
---------------------------------------------------------------------------------------------------------------------------------------- begin _gsieve ---
- version 7.0
- gettoken type 0 : 0
- gettoken g 0 : 0
- gettoken eqs 0 : 0
- syntax varname(string) [if] [in] [, KEEP(str) CHAR(str asis) OMIT(str asis) ]
- local nopts = ("`keep'" != "") + (`"`char'"' != "") + (`"`omit'"' != "")
= local nopts = ("" != "") + (`"0 1 2 3 4 5 6 7 8 9 . "' != "") + (`""' != "")
- if `nopts' != 1 {
= if 1 != 1 {
di as err "specify keep() or char() or omit()"
exit 198
}
- if `"`omit'"' != "" {
= if `""' != "" {
local char `"`omit'"'
local not "!"
}
- marksample touse, strok
- local type "str1"
- qui gen `type' `g' = ""
= qui gen str1 __000001 = ""
- local length : type `varlist'
= local length : type mhab
- local length = substr("`length'",4,.)
= local length = substr("strL",4,.)
- if "`keep'" != "" {
= if "" != "" {
local a 0
local n 0
local o 0
local s 0
foreach w of local keep {
local l = length("`w'")
if substr("alphabetic",1,max(1,`l')) == "`w'" {
local a 1
}
else if substr("numeric",1,max(1,`l')) == "`w'" {
local n 1
}
else if substr("other",1,max(1,`l')) == "`w'" {
local o 1
}
else if substr("spaces",1,max(1,`l')) == "`w'" {
local s 1
}
else {
di as err "keep() invalid"
exit 198
}
}
tempvar c
quietly {
gen str1 `c' = ""
forval i = 1 / `length' {
replace `c' = substr(`varlist',`i',1)
if `a' {
replace `g' = `g' + `c' if ((`c' >= "A" & `c' <= "Z") | (`c' >= "a" & `c' <= "z"))
}
if `n' {
replace `g' = `g' + `c' if (`c' >= "0" & `c' <= "9")
}
if `s' {
replace `g' = `g' + `c' if `c' == " "
}
if `o' {
replace `g' = `g' + `c' if !( (`c' >= "A" & `c' <= "Z") | (`c' >= "a" & `c' <= "z") | (`c' >= "0" & `c' <= "9") | (`c' == " ") )
}
}
}
}
- else {
- forval i = 1 / `length' {
= forval i = 1 / L {
invalid syntax
qui replace `g' = `g' + substr(`varlist',`i',1) if `not'index(`"`char'"', substr(`varlist',`i',1))
}
------------------------------------------------------------------------------------------------------------------------------------------ end _gsieve ---
- global EGEN_SVarname
- global EGEN_Varname
- if _rc { exit _rc }
----------------------------------------------------------------------------------------------------------------------------------------------- end egen ---
r(198);
Viewing all 73189 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>