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

Balance Table and Randomization

$
0
0
Hi, I am working with data of a random experiment. How ever, in my case of study, in a moment I lose information about 247 individuals. How can it affect to my results of OLS? How can determinated with a Balance Table that the randomization is still working? (what type of information can I use in the balance table?)

Thanks for your answer.

B.


Running ANCOVA with model assumptions testing across multiple random samples

$
0
0
I would be most grateful if you could advise me on the availability of pre-existing code that will allow me to run the model assumptions for ANCOVA in addition to running the ANCOVA process itself. I normally use SPSS for ANCOVA but I would like to run an ANCOVA and corresponding model assumptions testing over multiple random samples taken from a single sample. I had initially assumed that the bootstrap approach may be correct for this but I should clarify that the end I have in mind is not to obtain a summary result from bootstrapping. I simply wish to compare results from running an ANCOVA and corresponding model assumptions testing across multiple random samples of a fixed size. Therefore, I am also interested to know if a better approach would be to generate the random samples first, save them in separate columns of a spreadsheet and then run the ANCOVA and model assumptions testing across each column separately. I would welcome advice on the most efficient approach to take.

Many thanks!

Graphing a t-distribution

$
0
0
I'd like to draw a t-distribution with mean 2, std deviation .2 and 14 degrees of freedom.

Previously, I wrote the code for a normal distribution that looks like this:

Code:
   #delimit;
   twoway
   function y=normalden(x,claimed_mu,std_error), range(`=tick1' `=tick9')   ///
              graphregion(color(white)) clstyle(foreground) || 
   (scatteri 0 `=claimed_mu', mcolor(red)) (scatteri 0 `=sample_mean', mcolor(black)),
   plotregion(style(none))
   legend(off)
   xtitle("Sample means of weights of Kitti's hog-nosed bats (g), n=`=n'")
   xlabel(`=tick1' `=tick2' `=tick3' `=tick4' `=tick5' `=tick6' `=tick7' `=tick8' `=tick9', format(%6.4f))
   ylabel(none)
   yscale(off);
   #delimit cr
I looked at the help for tden, and ntden but wasn't able to write the code. Any assistance would be appreciated.

Getting precision weighted estimates using melogit

$
0
0
Hello Statausers,

I have a two-level logit model where I have used group centered variables along with group means. I have been advised to use precision weighted estimates instead of group means in my multilevel model. For this, I need to follow these directions
HTML Code:
"Calculate a separate null two level model with individual wealth as the outcome and then get precision weighted estimates of cluster wealth from this model . This estimate - the level 2 residual can then be used in your original model."
This was easy for binary variable "x". I used the following code:
Code:
svy:melogit x||psu: , 
    predict gm1, reffects
Note that though my model uses the ‘subpop’ command I I have not used it above because I want these estimates from the whole population. I hope that is right?

But I am not sure how to do this for categorical variables. I have multiple such variables such as education (4 categories) and household wealth (5 categories). Even for continuous variables, "mixed" does not allow using survey weights. So how do I go about that?

I will appreciate your advice.

Thank you
Deepali

How to interpret sigma_u (between subject) and sigma_e (within subject) in Fixed-effects model

$
0
0
Dear all,

I'm running a fixed-effects model and need help interpreting sigma_u (between subject) and sigma_e (within subject) because an assessor requested me to fully explain their meaning. I have uploaded the output of model below. My dependent variable is school-mean test scores in maths. The independent variables include the years of the tests were performed: pb2009, pb2011, pb2013 and pb2015 compared to the base category pb2007.

Any help will be highly appreciated.

Thank you.

Luana.

Difficulties in running xtabond2 command in stata v16

$
0
0
Dear all,
I just installed stata 16 IC and subsequently installed xtabond2 command. However, I often get error feedback from for a all the countless number of times I tried xtbond2 command. The following is the code and the error.

Code

xtabond2 imr l.imr gdp hegdp acces felr ge, ///gmm(l.imr,collapse) iv(gdp hegdp acces felr ge,) ///nodiffsargan noleveleq twostep robust orthogonal small


Error:

xtabond2 imr l.imr gdp hegdp acces felr ge, ///
Favoring space over speed. To switch, type or click on mata: mata set matafavor speed, perm.
/ / / invalid.r(198);

gmm(l.imr,collapse) iv(gdp hegdp acces felr ge,) ///
note: no parameters in equation 1
matrix __00000A not found
r(111);

nodiffsargan noleveleq twostep robust orthogonal small
command nodiffsargan is unrecognized
r(199);

I often get errors like nodiffsargan is unrecognized, twostep/onestep is unrecognized, robust, orthogonal is unrecognized, no paremeter in equation 1, factor variables may not contain noninteger values etc. Is it the case that I need to install other softwares to be able to use xtabond2? If so, what is it? Please, help me out. I am really confused. Thanks so much.

Possible bug in -bootstrap-

$
0
0
Currently, I only have access to Stata 11 to 14. In these releases, there appears to be a bug in bootstrap. Here is an example

Code:
// example data
webuse rate2 , clear

// we only keep the relevant variables
keep rada radb
describe

// estimate kappa coefficient
kap rada radb

// correct results with -bootstrap-
bootstrap kappa = r(kappa) : kap rada radb

// incorrect results with -bootstrap-
// probably because -bootstrap- includes its temporary variables
bootstrap kappa = r(kappa) : kap *
bootstrap appears to unabbreviate the passed variable list after it adds its own temporary variables to the dataset. This messes up the estimated coefficient(s). I have found, and reported to tech-support, a similar bug in egen. while ago. The latter has been fixed. Could someone replicate the above with Stata 15 and/or 16 and confirm that this is a bug?

Best
Daniel

Collapsing survival data

$
0
0
Dear all,

I have a very big data set with a survival structure that I want to compress/collapse. Right now the data look like this:
ID t0 t1 y x1 x2
1 0 1 0 0 0
1 1 2 0 0 0
1 2 3 0 3 1
1 3 4 0 2 1
1 4 5 0 2 1
1 5 6 1 2 0
1 6 7 0 1 0
1 7 8 0 2 1
1 8 9 1 2 1
t0 and t1 specify the start and end time, y is some outcome and x1 and x2 are time-varying variables.
What I want to do is to collapse spells of t0 t1 where none of the time-varying variables (including y) vary for a period.

In other words, I want to transform the data above to look like this:
ID t0 t1 y x1 x2
1 0 2 0 0 0
1 2 3 0 3 1
1 3 5 0 2 1
1 5 6 1 2 0
1 6 7 0 1 0
1 7 8 0 2 1
1 8 9 1 2 1

Example code:
Code:
input str1 id     t0         t1         y         x1         x2
        1        0        1        0        0        0    
        1        1        2        0        0        0
        1        2        3        0        3        1
        1        3        4        0        2        1
        1        4        5        0        2        1
        1        5        6        1        2        0
        1        6        7        0        1        0
        1        7        8        0        2        1
        1        8        9        1        2        1
end

Open password protected ".dta" file (I have the password)

$
0
0
Dear All,

I have received data files (.dta) which is protected with a password (I have the password), I couldn't open it in Stata!

Could you please help me on how to open this file.

Regards,

Problem with betamix

$
0
0
I am having a problem with betamix. Our dependent variable has a distribution whose characteristics are similar to the ones described in Pereira, Botter and Sandoval (2013) (https://journals.sagepub.com/doi/10....71082X13478274) with a fixed threshold (c): values in the range (0, 0.333) have been replaced by zero, so an inflation in zero occurs. Then we observe values in the interval [0.333,1], with a distribution skewed to the right.
We need to estimate:
  1. the discrete change in the probability of the dependent variable acquiring a value of zero (and its significance), given the values of a dummy variable (DUM). We attempted to use the mchange command, but it is invalid for betamix. The command does provide the odds ratio, but this is not the result we need.
  2. The difference in the mean value of the beta mixture part of the model strictly (without taking into account the zeros) conditional on DUM, and its significance. We attempted to calculate margins, but the mean we obtain takes into account the zeros in the lower bound, so it is not the information we need.
  3. The difference in the predicted value of the dependent variable as a whole, conditional on DUM. We are using the command “margin r.DUM” and we obtain the desired results and corresponding significance.
In our estimation, we include DUM as follows (where a=0.333):
betamix depvar, muvar(i.DUM …covariates…) pmvar(i.DUM …covariates…) lbound(0) ubound(1) trun(bottom) tbound(`a') pmass(0 0 1) vce(cluster var)
Can anyone please suggest some alternative command we can use to extract results (1) and (2) from the estimated model?

Dealing with zero values

$
0
0
Hello,
I am working on the effect of social transfers (pensions and other social benefits) on middle income class by employing EU-SILC. My question is how can I effectively handle a lot of zero values on the respective indicators.
Thank you,
Stefanos

Reporting weighted vs. unweighted data in descriptive analysis

$
0
0
Dear Stata Community:

I am using a large nationally representative dataset where data is nested (children within schools within districts, etc.) and where populations (Asian and Native American children) were oversampled to attain a large enough sample size for these groups. As a result, for statistical analysis, I need to weight the sample using the .svyset command. My question is, when reporting the sample means and SD's for descriptive purposes only, do I report the weighted or unweighted numbers?
Many thanks,
Pat

Issues with Lincom command

$
0
0
Hello,
I posted this question a few days ago, and I am trying to use the lincom command to find the P-test, t-test, confidence interval and coefficient between two variables. This is actually for a Stata-led statistics class as I am a Ph.D. student. All the lincom examples given in the text and the variables asked in the homework all result in the same error. Below is my Do-file for an example:

mean egalitarianism [pw=nesw], over(Female)
lincom [egalitarianism]Male - [egalitarianism]Female


However, with lincom I continue to get the same error command:

equation [egalitarianism] not found
r(303);


Does anyone have suggestions I may use to find the same needed results without using the lincom command?

Heckman selection model in three stages

$
0
0
Dear Statalist,
I hope you are well. Please, I would like to ask regarding the Heckman selection model, how to apply it with my categorical data. In fact, I have four categories in one column referred to as dependent variables. At first, I have analyzed the estimation of these variables using Multinomial logit regression. However, in order to test the selection bias, have been advised to apply Heckman probit selection model using Stata.
My question is how to apply the hackman model over the four dependent variables? Do I need first to create a sperate table of dataset for each dependent variable? Or can I keep them in one column and the software is intelligent to select the required dependent variable for each stage? Regarding the Stata command, should I use the syntax command for each stage with only changing the dependent variable?



The command: heckman depvar [indepvars], select(depvars = varlists) [twostep]
I have 300 firms as sample size; dealing with 32 independent variables. Each firm has to choose one decision of the four categories (i.e. dependent variables). The below Table shows my idea to employ the analysis of hackman over the dependent variables in three stages.
Could you please advise me on how to apply the Heckman model for the 3 stages?
Stage 1 analyzing all firms (300 n) Stage 2 Analyzing Firm B Stage 3 Analysing Firm C
dependent variable Firm decide A (87n)
dependent variable Firm decide C (103 n)
dependent variable Firm decide E (83n)
dependent variable Firm decide B(213 n)
dependent variable Firm decide D (110 n)
dependent variable Firm decide F (20n)
Note: the letters from A to F is the type of firms’ decision and is considered to be the dependent variable. (n) refer to the number of firms in each category of the dependent variable

Your kind help and support greatly appreciated
Kind regards,
Rabab



Tokenize and looping through tokens

$
0
0
Hi Statlist,

I have the following problem. I have defined 3 local variables defining the path to some folders containing 3 different .dta files.
What I would like to do actually is open each file separately and work on it in a single loop. The pseudo code should read something like this:

Code:
local folder_product "/Users/federiconutarelli/Desktop/PhD/Lavoro_Riccaboni/DATi_USA/Pharma_project_2019 /prodmol_aggregation"
local folder_firm "/Users/federiconutarelli/Desktop/PhD/Lavoro_Riccaboni/DATi_USA/Pharma_project_2019 /firm_aggregation"
local folder_atc2 "/Users/federiconutarelli/Desktop/PhD/Lavoro_Riccaboni/DATi_USA/Pharma_project_2019 /ATC_aggregation"

local aggr "product firm atc2"
tokenize `aggr' // syntax (cfr help tokenize)

foreach y in `aggr'{
local filelist: dir "`folder_"+`1' files "DB_" + `1'  + "_aggregation.dta" // where `1' should be "product" in the token right?
foreach file of local filelist {
  use "`file'", clear
[DO SOME STUFFS]
}
local filelist: dir "`folder_"+`2' files "DB_" + `2'  + "_aggregation.dta" // where `2' should be "firm"
foreach file of local filelist {
  use "`file'", clear
[DO SOME STUFFS]
}
local filelist: dir "`folder_"+`3' files "DB_" + `3'  + "_aggregation.dta" // where `3' should be "atc2" in the token right?
foreach file of local filelist {
  use "`file'", clear
[DO SOME STUFFS]
}
}
Of course it does not work but I cannot figure out why. Can someone please help me?

Thanks,

Federico

Should I rename all the variables with the year immediately following the original variable names when I merge data across years with loop

$
0
0
I run the following code:

local i = 1998
while `i' < 2007{

local j=`i'+1


**step 10: match by firm ID**

*deal with duplicates of IDs (there are a few firms that have same IDs)*
use m`i'.10.dta, clear
bysort id`i': keep if _N>1
save duplicates_ID`i'.dta, replace

use m`i'.10.dta, clear
bysort id`i': drop if _N>1
rename id`i' id
rename B210 stateown
rename F301 capital_total
rename F302 capital_state
rename F392 capital_collective
rename F393 capital_legal
rename F394 capital_individual
rename F395 capital_HMT
rename F303 capital_foreign
rename product1_ product
keep bdat`i' cic`i' dq`i' capital_total`i' capital_state`i' capital_collective`i' capital_legal`i' capital_individual`i' capital_HMT`i' capital_foreign`i' stateown`i' id legal_person`i' name`i' phone`i' product`i' town`i'
sort id
save match`i'.1.dta, replace

use m`j'.10.dta, clear
bysort id`j': keep if _N>1
save duplicates_ID`j'.dta, replace

use m`j'.10.dta, clear
bysort id`j': drop if _N>1
rename id`j' id
keep bdat`j' cic`j' dq`j' capital_total`j' capital_state`j' capital_collective`j' capital_legal`j' capital_individual`j' capital_HMT`j' capital_foreign`j' stateown`j' id legal_person`j' name`j' phone`j' product`j' town`j'
sort id
save match`j'.1.dta, replace

use match`i'.1.dta, clear
merge id using match`j'.1.dta
keep if _merge==3
gen id`i'=id
rename id id`j'
drop _merge
gen match_method_`i'_`j'="ID"
gen match_status_`i'_`j'="3"
save matched_by_ID`i'_`j'.dta, replace



**step 20: match by firm names**

*match those unmatched firms in previous step by firm names*

use match`i'.1.dta, clear
merge id using match`j'.1.dta
keep if _merge==1
rename id id`i'
append using duplicates_ID`i'.dta
bysort name`i': keep if _N>1
keep bdat`i' cic`i' dq`i' capital_total`i' capital_state`i' capital_collective`i' capital_legal`i' capital_individual`i' capital_HMT`i' capital_foreign`i' stateown`i' id`i' legal_person`i' name`i' phone`i' product`i' town`i'
save duplicates_name`i'.dta, replace

use match`i'.1.dta, clear
merge id using match`j'.1.dta
keep if _merge==1
rename id id`i'
append using duplicates_ID`i'.dta
bysort name`i': drop if _N>1
rename name`i' name
sort name
keep bdat`i' cic`i' dq`i' capital_total`i' capital_state`i' capital_collective`i' capital_legal`i' capital_individual`i' capital_HMT`i' capital_foreign`i' stateown`i' id`i' legal_person`i' name`i' phone`i' product`i' town`i'
save unmatched_by_ID`i'.dta, replace

use match`i'.1.dta, clear
merge id using match`j'.1.dta
keep if _merge==2
rename id id`j'
append using duplicates_ID`j'.dta
bysort name`j': keep if _N>1
keep bdat`j' cic`j' dq`j' capital_total`j' capital_state`j' capital_collective`j' capital_legal`j' capital_individual`j' capital_HMT`j' capital_foreign`j' stateown`j' id`j' legal_person`j' name`j' phone`j' product`j' town`j'
save duplicates_name`j'.dta, replace

use match`i'.1.dta, clear
merge id using match`j'.1.dta
keep if _merge==2
rename id id`j'
append using duplicates_ID`j'.dta
bysort name`j': drop if _N>1
rename name`j' name
sort name
keep bdat`j' cic`j' dq`j' capital_total`j' capital_state`j' capital_collective`j' capital_legal`j' capital_individual`j' capital_HMT`j' capital_foreign`j' stateown`j' id`j' legal_person`j' name`j' phone`j' product`j' town`j'
save unmatched_by_ID`j'.dta, replace

use unmatched_by_ID`i'.dta, clear
merge name using unmatched_by_ID`j'.dta
keep if _merge==3
gen name`i'=name
rename name name`j'
drop _merge
gen match_method_`i'_`j'="firm name"
gen match_status_`i'_`j'="3"
save matched_by_name`i'_`j'.dta, replace



**step 30: match by the names of legal person representatives**

*match those unmatched firms in previous steps by firm legal person representatives*

use unmatched_by_ID`i'.dta, clear
merge name using unmatched_by_ID`j'.dta
keep if _merge==1
rename name name`i'
append using duplicates_name`i'.dta
replace legal_person`i'="." if legal_person`i'==""
gen code1=legal_person`i'+substr(dq`i',1,4)
bysort code1: keep if _N>1
keep bdat`i' cic`i' dq`i' capital_total`i' capital_state`i' capital_collective`i' capital_legal`i' capital_individual`i' capital_HMT`i' capital_foreign`i' stateown`i' id`i' legal_person`i' name`i' phone`i' product`i' town`i'
save duplicates_code1_`i'.dta, replace

use unmatched_by_ID`i'.dta, clear
merge name using unmatched_by_ID`j'.dta
keep if _merge==1
rename name name`i'
append using duplicates_name`i'.dta
replace legal_person`i'="." if legal_person`i'==""
gen code1=legal_person`i'+substr(dq`i',1,4)
bysort code1: drop if _N>1
sort code1
keep code1 bdat`i' cic`i' dq`i' capital_total`i' capital_state`i' capital_collective`i' capital_legal`i' capital_individual`i' capital_HMT`i' capital_foreign`i' stateown`i' id`i' legal_person`i' name`i' phone`i' product`i' town`i'
save unmatched_by_ID_and_name`i'.dta, replace

use unmatched_by_ID`i'.dta, clear
merge name using unmatched_by_ID`j'.dta
keep if _merge==2
rename name name`j'
append using duplicates_name`j'.dta
gen code1=legal_person`j'+substr(dq`j',1,4)
bysort code1: keep if _N>1
keep bdat`j' cic`j' dq`j' capital_total`j' capital_state`j' capital_collective`j' capital_legal`j' capital_individual`j' capital_HMT`j' capital_foreign`j' stateown`j' id`j' legal_person`j' name`j' phone`j' product`j' town`j'
save duplicates_code1_`j'.dta, replace

use unmatched_by_ID`i'.dta, clear
merge name using unmatched_by_ID`j'.dta
keep if _merge==2
rename name name`j'
append using duplicates_name`j'.dta
gen code1=legal_person`j'+substr(dq`j',1,4)
bysort code1: drop if _N>1
sort code1
keep code1 bdat`j' cic`j' dq`j' capital_total`j' capital_state`j' capital_collective`j' capital_legal`j' capital_individual`j' capital_HMT`j' capital_foreign`j' stateown`j' id`j' legal_person`j' name`j' phone`j' product`j' town`j'
save unmatched_by_ID_and_name`j'.dta, replace

use unmatched_by_ID_and_name`i'.dta, clear
display _N
merge code1 using unmatched_by_ID_and_name`j'.dta
keep if _merge==3
drop _merge code1
gen match_method_`i'_`j'="legal person"
gen match_status_`i'_`j'="3"
save matched_by_legalperson`i'_`j'.dta, replace



**step 40: match by phone number + city code**

*match those unmatched firms in previous steps by phone number + city code*

use unmatched_by_ID_and_name`i'.dta, clear
merge code1 using unmatched_by_ID_and_name`j'.dta
keep if _merge==1
drop code1
append using duplicates_code1_`i'
replace phone`i'="." if phone`i'==""
gen code2=substr(dq`i',1,4)+substr(cic`i',1,3)+phone`i '
bysort code2: keep if _N>1
keep bdat`i' cic`i' dq`i' capital_total`i' capital_state`i' capital_collective`i' capital_legal`i' capital_individual`i' capital_HMT`i' capital_foreign`i' stateown`i' id`i' legal_person`i' name`i' phone`i' product`i' town`i'
save duplicates_code2_`i'.dta, replace

use unmatched_by_ID_and_name`i'.dta, clear
merge code1 using unmatched_by_ID_and_name`j'.dta
keep if _merge==1
drop code1
append using duplicates_code1_`i'
replace phone`i'="." if phone`i'==""
gen code2=substr(dq`i',1,4)+substr(cic`i',1,3)+phone`i '
bysort code2: drop if _N>1
sort code2
keep code2 bdat`i' cic`i' dq`i' capital_total`i' capital_state`i' capital_collective`i' capital_legal`i' capital_individual`i' capital_HMT`i' capital_foreign`i' stateown`i' id`i' legal_person`i' name`i' phone`i' product`i' town`i'
save unmatched_by_ID_and_name_and_legalperson`i'.dta, replace


use unmatched_by_ID_and_name`i'.dta, clear
merge code1 using unmatched_by_ID_and_name`j'.dta
keep if _merge==2
drop code1
append using duplicates_code1_`j'
gen code2=substr(dq`j',1,4)+substr(cic`j',1,3)+phone`j '
bysort code2: keep if _N>1
keep bdat`j' cic`j' dq`j' capital_total`j' capital_state`j' capital_collective`j' capital_legal`j' capital_individual`j' capital_HMT`j' capital_foreign`j' stateown`j' id`j' legal_person`j' name`j' phone`j' product`j' town`j'
save duplicates_code2_`j'.dta, replace

use unmatched_by_ID_and_name`i'.dta, clear
merge code1 using unmatched_by_ID_and_name`j'.dta
keep if _merge==2
drop code1
append using duplicates_code1_`j'
gen code2=substr(dq`j',1,4)+substr(cic`j',1,3)+phone`j '
bysort code2: drop if _N>1
sort code2
keep code2 bdat`j' cic`j' dq`j' capital_total`j' capital_state`j' capital_collective`j' capital_legal`j' capital_individual`j' capital_HMT`j' capital_foreign`j' stateown`j' id`j' legal_person`j' name`j' phone`j' product`j' town`j'
save unmatched_by_ID_and_name_and_legalperson`j'.dta, replace

use unmatched_by_ID_and_name_and_legalperson`i'.dta,cl ear
merge code2 using unmatched_by_ID_and_name_and_legalperson`j'.dta
keep if _merge==3
drop _merge code2
gen match_method_`i'_`j'="phone number"
gen match_status_`i'_`j'="3"
save matched_by_phone`i'_`j'.dta, replace



**step 50: match by code = founding year + geographic code + industry code + name of town + name of main product**

*match those unmatched firms in previous steps by founding year + geographic code + industry code + name of town + name of main product*

use unmatched_by_ID_and_name_and_legalperson`i'.dta,cl ear
merge code2 using unmatched_by_ID_and_name_and_legalperson`j'.dta
keep if _merge==1
drop code2
append using duplicates_code2_`i'.dta
replace town`i'="." if town`i'==""
replace product1_`i'="." if product1_`i'==""
gen code3=bdat`i'+substr(dq`i',1,6)+substr(cic`i',1,4) +town`i'+product1_`i'
bysort code3: keep if _N>1
keep bdat`i' cic`i' dq`i' capital_total`i' capital_state`i' capital_collective`i' capital_legal`i' capital_individual`i' capital_HMT`i' capital_foreign`i' stateown`i' id`i' legal_person`i' name`i' phone`i' product`i' town`i'
save duplicates_code3_`i'.dta, replace

use unmatched_by_ID_and_name_and_legalperson`i'.dta,cl ear
merge code2 using unmatched_by_ID_and_name_and_legalperson`j'.dta
keep if _merge==1
drop code2
append using duplicates_code2_`i'.dta
replace town`i'="." if town`i'==""
replace product1_`i'="." if product1_`i'==""
gen code3=bdat`i'+substr(dq`i',1,6)+substr(cic`i',1,4) +town`i'+product1_`i'
bysort code3: drop if _N>1
sort code3
keep code3 bdat`i' cic`i' dq`i' capital_total`i' capital_state`i' capital_collective`i' capital_legal`i' capital_individual`i' capital_HMT`i' capital_foreign`i' stateown`i' id`i' legal_person`i' name`i' phone`i' product`i' town`i'
save unmatched_by_ID_and_name_and_legalperson_and_phone `i'.dta, replace

use unmatched_by_ID_and_name_and_legalperson`i'.dta,cl ear
merge code2 using unmatched_by_ID_and_name_and_legalperson`j'.dta
keep if _merge==2
drop code2
append using duplicates_code2_`j'.dta
gen code3=bdat`j'+substr(dq`j',1,6)+substr(cic`j',1,4) +town`j'+product1_`j'
bysort code3: keep if _N>1
keep bdat`j' cic`j' dq`j' capital_total`j' capital_state`j' capital_collective`j' capital_legal`j' capital_individual`j' capital_HMT`j' capital_foreign`j' stateown`j' id`j' legal_person`j' name`j' phone`j' product`j' town`j'
save duplicates_code3_`j'.dta, replace

use unmatched_by_ID_and_name_and_legalperson`i'.dta,cl ear
merge code2 using unmatched_by_ID_and_name_and_legalperson`j'.dta
keep if _merge==2
drop code2
append using duplicates_code2_`j'.dta
gen code3=bdat`j'+substr(dq`j',1,6)+substr(cic`j',1,4) +town`j'+product1_`j'
bysort code3: drop if _N>1
sort code3
keep code3 bdat`j' cic`j' dq`j' capital_total`j' capital_state`j' capital_collective`j' capital_legal`j' capital_individual`j' capital_HMT`j' capital_foreign`j' stateown`j' id`j' legal_person`j' name`j' phone`j' product`j' town`j'
save unmatched_by_ID_and_name_and_legalperson_and_phone `j'.dta, replace

use unmatched_by_ID_and_name_and_legalperson_and_phone `i'.dta,clear
display _N
merge code3 using unmatched_by_ID_and_name_and_legalperson_and_phone `j'.dta
keep if _merge==3
drop _merge code3
gen match_method_`i'_`j'="code 3"
gen match_status_`i'_`j'="3"
save matched_by_code3_`i'_`j'.dta, replace

use unmatched_by_ID_and_name_and_legalperson_and_phone `i'.dta,clear
merge code3 using unmatched_by_ID_and_name_and_legalperson_and_phone `j'.dta
keep if _merge==1
drop _merge code3
append using duplicates_code3_`i'.dta
gen match_method_`i'_`j'=""
gen match_status_`i'_`j'="1"
save unmatched_by_ID_and_name_and_legalperson_and_phone _and_code2_`i'.dta, replace

use unmatched_by_ID_and_name_and_legalperson_and_phone `i'.dta,clear
merge code3 using unmatched_by_ID_and_name_and_legalperson_and_phone `j'.dta
keep if _merge==2
drop _merge code3
append using duplicates_code3_`j'.dta
gen match_method_`i'_`j'=""
gen match_status_`i'_`j'="2"
save unmatched_by_ID_and_name_and_legalperson_and_phone _and_code2_`j'.dta, replace



**step 60: merge the matched and unmatched files to create files of two consecutive years**

use matched_by_ID`i'_`j'.dta, clear
append using matched_by_name`i'_`j'.dta
append using matched_by_legalperson`i'_`j'.dta
append using matched_by_phone`i'_`j'.dta
append using matched_by_code3_`i'_`j'.dta
append using unmatched_by_ID_and_name_and_legalperson_and_phone _and_code2_`i'.dta
append using unmatched_by_ID_and_name_and_legalperson_and_phone _and_code2_`j'.dta
save m`i'-m`j'.dta, replace


local i = `i' + 1
}

But I got this error showed after:

(165,116 observations deleted)
file duplicates_ID1998.dta saved
(2 observations deleted)
variable bdat1998 not found
r(111);

How should I solve the problem? I have to rename all the variables with the year immediately following the original variable names even in this loop command? Am I clear with my question?

Your help will be greatly appreciated!

Error Using the Command 'using'

$
0
0
Hello everyone,

I just downloaded data from PSID. Every time I run the do.file that comes with the data, I get an error.
The error occurs on the following line:
Code:
using "/Users/Desktop/PSID/Compiled"\J266327.txt, clear
I appreciate any help on how to solve the issue.

Best,
Hussain Hadah

Creating a variable with three condtions

$
0
0
I am using a data set of 50 countries which are separated into four regions.
I want to create a variable of regional contagion, where recgontagion for country j takes one if and only if there is a crisis in at least one country other than country j and this country is in the same region as country j.

I have been the below command but it doesn't work:

replace regcontagion=1 if (evnt3w==1&country!=country &region_id==region_id)












Rescaling Time

$
0
0
Hi Statlist,

I have the following problem. I have a panel dataset of the form:
Code:
* Example generated by -dataex-. To install: ssc install dataex
clear
input float(dummy_1 idproduct Year)
0  1 2010
0  1 2011
0  1 2012
0  2 2004
0  2 2005
0  2 2006
0  2 2007
0  3 2004
0  4 2012
0  4 2013
0  5 2010
0  5 2011
0  6 2010
0  6 2011
0  6 2012
0  7 2007
0  7 2008
0  8 2004
0  8 2015
0  9 2004
0  9 2005
0  9 2006
0  9 2007
0  9 2008
0  9 2009
0  9 2010
0  9 2011
0  9 2012
0  9 2013
0  9 2014
0  9 2015
0 10 2010
0 10 2011
0 10 2012
0 11 2004
0 11 2005
0 11 2006
0 11 2007
0 11 2008
0 11 2009
0 11 2010
0 11 2011
0 11 2012
0 11 2013
0 11 2014
0 11 2015
0 12 2008
0 12 2009
0 12 2010
0 12 2011
0 12 2012
0 12 2013
0 12 2014
0 12 2015
0 13 2010
0 13 2011
0 13 2012
1 14 2004
0 14 2005
0 14 2006
0 14 2007
0 14 2008
0 14 2009
0 14 2010
0 14 2011
0 14 2012
0 14 2013
0 14 2015
0 15 2004
0 15 2005
1 15 2006
0 15 2007
0 15 2008
0 15 2010
1 15 2011
0 15 2012
0 15 2013
0 16 2004
0 16 2005
0 16 2006
0 16 2007
0 16 2008
0 16 2009
0 16 2010
0 16 2011
0 16 2012
0 16 2013
0 16 2014
0 16 2015
0 17 2008
0 17 2009
0 17 2010
0 18 2004
0 18 2005
0 18 2009
0 18 2010
1 18 2011
1 18 2012
0 18 2013
0 18 2014
end
Hence, the data consists of products observed in time (unbalanced panel). I also have a dummy variable taking 1 if the product has been recalled in a Year and 0 if not. What I would like to do is basically rescaling the time variable Year for each product with respect to the Year in which it received the recall. SO for instance if the product 3, observed in 2005 2006 2007 and 2008 received a recall in 2007, 2007 should be year 0, 2005 = -2, 2006 = -1, 2007 = 0, 2008 = 1 and so on. I have managed to this. The problem is when more than a recall occurs in a time span. Specifically, say idproduct 18 in the data above. Idprod 18 receives 2 recalls one in 2011 and one in 2012. For such kinds of products (and also the ones receiving more than 2 recalls) I would like to rescale time by splitting it into two rescaled time putting the year in common as "pre" of the "younger" recall and "post" of the "elder". So in the case of product 18 I would like to obtain something like:

Code:
input float(dummy_1 idproduct Year rescaled_year)
0 18 2004 -4
0 18 2005 -3
0 18 2009 -2
0 18 2010 -1
1 18 2011. 0
1 18 2012.  0
0 18 2013  1
0 18 2014  2
And for product 15 (which has years in common due to the fact that the recalls are separated):
Code:
input float(dummy_1 idproduct Year rescaled_year)
0 15 2004 -2
0 15 2005 -1
1 15 2006 0
0 15 2007 1; -3
0 15 2008 2; -2
0 15 2010 3; -1
1 15 2011 0
0 15 2012 1
0 15 2013 2
I don't know if the output is correct: indeed the variable rescaled_year should be eventually, plot on the x-axis of a graphic (so two values for a same rescaled_year are not convenient I guess) The point is that I am looking for a way to split into two the spans of the recalls: the first in 2006 should look: -2, -1, 0,1, 2 , 3; the second in 2011: -1, 0,1,2.
Please notice that this should extend to the case in which I have 3,4 and 5 recalls.
So, for instance had idpr 15 had 3 recalls, this should have been:

Code:
input float(dummy_1 idproduct Year rescaled_year)
0 15 2004 -1
1 15 2005 0
1 15 2006 0
0 15 2007 1; -3
0 15 2008 2; -2
0 15 2010 3; -1
1 15 2011 0
0 15 2012 1
0 15 2013 2

Sorry for the length of the post and thank you in advance!

Federico

xtreg regression leaves out one country for i.country

$
0
0
Hello everyone,

For my thesis, I am aming on extracting country fixed effects on the perception of migrants. For that purpose, my supervisor instructed me to use the *xtreg* command.

As you can see below, when I use *tab cntry*, I have 20 countries including EE = Estonia:
Array


But after using:
xtset cntry
xtrereg patm trstun trstep i.safe i.strgov i.trad i.rule imp_eco imp_cult lrscale ecoinsec i.hinctnta sex i.agebrack eduyrs highschool apprentice undergrad postgrad i.cntry, vce(robust)
I receive the following output for the country variables:
Array

As you can see, EE = Estonia is not included anymore. Why is that?

I already tried removing vce(robust) or to replace it by vce(country = robust).

Interestingly, I am working with the data from the Eurobarometer. This is for ESS7 in 2014. I already did the same regression on ESS8 in 2016 and I did not have that issue.

Can anyone help me?

Thank you very much in advance for your help!
Aileen
Viewing all 72807 articles
Browse latest View live


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