How to to this with a formula?

Thank you for your help.

]]>

i want to estimate the effect of preferences on education spending from a household

i only want to observe the Head of HH with children age 7-23

but how to assign the info on head of HH, if the data is mixed by head of HH and its children

Code:

* Example generated by -dataex-. For more info, type help dataex clear input str10 hhid14_9 double(pid14 ar02b) "001060000" 1 1 "001060000" 7 2 "001060000" 8 3 "001060000" 8 3 "001060000" 8 3 "001060000" 8 3 "001060000" 8 3 "001060000" 8 3 "001060000" 8 3 "001060000" 8 3 "001060000" 9 3 "001060000" 10 3 "001060000" 11 3 "001060004" 1 2 "001060004" 2 1 "001060004" 2 1 "001060004" 2 1 "001060004" 2 1 "001060004" 2 1 "001060004" 2 1 "001060004" 2 1 "001060004" 2 1 "001060004" 2 1 "001060004" 2 1 "001060004" 3 3 "001060004" 4 3 "001080000" 8 1 "001080003" 1 1 "001080003" 2 2 "001080003" 3 3 "001080003" 4 3 "001080003" 5 3 "001080003" 6 3 "001080003" 6 3 "001080003" 6 3 "001080003" 6 3 "001080003" 6 3 "001080003" 6 3 "001080003" 6 3 "001080003" 7 3 "001220000" 1 1 "001220000" 1 1 "001220000" 1 1 "001220000" 1 1 "001220000" 1 1 "001220000" 1 1 "001220000" 1 1 "001220000" 1 1 "001220000" 1 1 "001220000" 2 2 "001220000" 6 3 "001220000" 14 3 "001220000" 15 3 "001220009" 1 1 "001224100" 1 1 "001224100" 2 2 "001224100" 3 3 "001224100" 4 3 "001224100" 5 3 "001224100" 5 3 "001224100" 5 3 "001224100" 5 3 "001224100" 5 3 "001224100" 5 3 "001224100" 5 3 "001224100" 5 3 "001224100" 6 3 "001224200" 1 1 "001240000" 2 1 "001240000" 3 3 "001240000" 4 3 "001240000" 7 3 "001240000" 12 10 "001240000" 14 3 "001240000" 16 10 "001240000" 17 10 "001240000" 18 10 "001240000" 19 10 "001240000" 20 10 "001240000" 21 10 "001240000" 22 10 "001240000" 23 10 "001240000" 24 17 "001240000" 25 5 "001240005" 1 1 "001240005" 2 2 "001240005" 2 2 "001240005" 2 2 "001240005" 2 2 "001240005" 2 2 "001240005" 2 2 "001240005" 2 2 "001240005" 2 2 "001240005" 2 2 "001240005" 2 2 "001240005" 2 2 "001240005" 2 2 "001240005" 2 2 "001240005" 2 2 "001240005" 2 2 end label values ar02b ar02b label def ar02b 1 "1:Head of the household", modify label def ar02b 2 "2:Husband/wife", modify label def ar02b 3 "3:Children (biological", modify label def ar02b 5 "5:Sons/daughters-in-law", modify label def ar02b 10 "10:Grandchild", modify label def ar02b 17 "17:Non-relative", modify

many thanks

]]>

I have run my LOGIT regression and now I want to obtain the marginal effect at the median for each single variable, while all the others shall be equal to zero. The following code in yellow and output do it that , but keep the other variables at their median level. How can I play around the code so to obtain what the desired outcome initially described?

Many Thanks!

Best

Linda

--------------------------------------------------------------------------------

Array ]]>

I hope I explain this clearly and with enough information, please let me know if I can provide more information. I need to calculate age (in years) for summary statistics. I have the 'dob' variable in a format such as 08/13/1950 and the 'medicationscantime' variable as 11/25/2000 8:45:00PM. How do I subtract 'medicationscantime' from 'dob' to get age in years? I have STATA 15.1]]>

I am currently specifying the group variable as a second dependent variable in the equation and referring to it in the evaluator using the global $ML_y2. It works, but If there is a easier way I would happily adopt.

Thanks!]]>

I frequently find that I want to produce line graphs of times series of categorical variables using survey data.

For instance, to just use a simple example, let's say I want to use the American Community Survey (a large, nationally-representative household survey of the US population) to produce a line graph of the annual rate of uninsurance among 4 different race/ethnic groups. Here, race4cat is a 4-level categorical variable of race. Uninsured = 1 if uninsured and 0 if insured. I have already svyset the data using pweights, cluster, and strata variables. Year is 2009-2018.

Code:

svy, subpop(if race4cat == 1): tabulate uninsured year, column percent svy, subpop(if race4cat == 2): tabulate uninsured year, column percent svy, subpop(if race4cat == 3): tabulate uninsured year, column percent svy, subpop(if race4cat == 4): tabulate uninsured year, column percent

Code:

collapse (mean) uninsuredavg=uninsured [pweight=perwt], by(year race4cat)

Code:

twoway (connected uninsuredavg year if race4cat == 1) /// (connected uninsuredavg year if race4cat == 2), /// (connected uninsuredavg year if race4cat == 3), /// (connected uninsuredavg year if race4cat == 4)

My two questions are:

1. Is there a less roundabout way to graph survey tabulation results than collapsing the database as I have done?

2. Assuming no, is there a way to graph confidence intervals?

Many thanks in advance!

Adam]]>

Taking the example that Stata uses under ''help nlogit'; following is the equation that is estimated and the results thereof:

nlogitgen type = restaurant(fast: Freebirds | MamasPizza, family: CafeEccell | LosNortenos | WingsNmore, fancy: Christophers | MadCows)

///Results from the above nlogit regression are:

Array ]]>

how I make the number of observation same ?

Array ]]>

Thank you for your advice. ]]>

I'm using STATA 16.0 to develop recreational demand function via using NBSTRAT model. I have several factor and continuous variables that force me to use "xi:" prefix in the model syntax because "nbstrat" is user-written command which is not allowed to use factor variables without this prefix.

Here is the code that I use:

Code:

xi: nbstrat S8_y i.Ad S6_RC_En S13_dogal S13_engelli S13_profil S15_RC_Tek i.S31_RCTip S33_RC_Yesil i.S38_Arac S7_yil S14_Ortak S14_Alis S14_Engel S14_Guvenlik S16_Mal S23_puan S34_uzak S36_Gelir, vce(robust)

Code:

margins, dydx(*) vce(unconditional)

Code:

. margins, dydx(*) vce(unconditional) cannot compute vce(unconditional); predict after ml could not compute scores r(322);

I will appreciate it if anyone helps me with that issue.

Kind regards

]]>

the following reference describes the use of repeated options in Stata:

https://www.stata.com/manuals/g-4con...tedoptions.pdf

I do not find, though, a description of declaring commands that support repeated options.

I'd like to declare a command that would support syntax such as

mycmd , optname(x y "some text label) optname(z t "some other label") optname(u v "yet another text label) opt1() opt2() .....

I believe repeated options are standard for graphing commands, where I can find an example of e.g. merging multiple

Ideally, I'd like the syntax to be something like: syntax , optname(string repeated)

then `optname' should evaluate to `"`"x y "some text label""' `"z t "some other label""' `"u v "yet another text label""'"'

with which I can later do word 1, word 2, etc. to obtain individual triplets.

A head on approach results in an error:

Code:

program define foobar version 16.0 syntax , myoption(string) display `"`myoption'"' end . foobar, myoption("1") myoption("2") option myoption() not allowed

Any advice is welcomed.

Thank you, Sergiy]]>

I have been using data from the Rush Memory and Aging Project to examine the relationship between sugar intake and cognition in older adults. Here is the code I am using:

capture program drop runsome

program define runsome, rclass

*Some code has been omitted

local i = 2

foreach v of varlist cogn_global cogn_ep cogn_se cogn_po cogn_ps cogn_wo {

local let : word `i' of `c(ALPHA)'

xtmixed `v' c.$predictor#c.studytime c.calor c.alco c.minddiet15_sc c.carb c.fiber c.$predictor c.studytime c.late_life_cogact || projid: studytime, cov(unstruct)

matrix results = r(table)

/*This is the part I am having trouble with*/

matrix N[i,1] = e(N_g)

mata: min(st_matrix("N")

mata: min(st_matrix("N"))

mata: st_local("min",strofreal(min(st_matrix("N"))))

local n = `min'

/*end of section*/

local n : di %-7.0gc `n'

putexcel set "$results\Table $t", sheet("Table feeder") modify

putexcel A11 = "Model 1 (n=`n')" `let'12=results[1,1] `let'13=results[2,1] `let'14=results[4,1]

local i = `i' + 1

matrix N = e(N_g)

local n = N[1,1]

local n : di %-7.0gc `n'

putexcel set "$results\Table $t", sheet("Table feeder") modify

putexcel A15 = "Model 2 (n=`n')"`let'16=results[1,1] `let'17=results[2,1] `let'18=results[4,1]

local i = `i' + 1

}

global t "3"

foreach v of varlist qsugtot qsucr qfruct qglu qmalt qlact qmind {

global predictor "`v'"

runsome

global t=$t+1

}

The core program outputs the regression coefficient, standard error, p-value and effective sample size (e(N_g)) to Excel. The program loops over the six outcome variables (cogn_global, cogn_ep...) and seven exposure variables (qsugtot, qfruct...). I want to store the effective sample size from each of the mixed effects regression models as a single row matrix, then I want to pick the smallest effective sample size and report this with the model statement (putexcel A11 = "Model 1 (n=`n')...). I have uploaded a limited dataset for reference. Would very much appreciate your help in finding a solution to this problem. Thanks kindly.

Chris

]]>

I am attempting to set up intervals using person id numbers (pid) and dates. The dates each correspond to a visit (visitn). I would like my data to be structured so that each row corresponds to an interval. The start date of interval 1 for each person is 9/1/19. The end date for interval 1 would be the date of visitn=1 for each person. The second interval would start on that same date (date of visitn=1) and would end EITHER at the date of visitn=2 OR if there is no visit 2, on 9/30/20.

I'm ultimately trying to create a dataset that looks like this:

Interval# | PID | start | end | duration (in days) | |

1 | 1 | 9/1/19 | 12/1/19 | ||

2 | 1 | 12/1/19 | 3/1/20 | ||

3 | 1 | 3/1/20 | 9/30/20 | ||

1 | 2 | 9/1/19 | 2/3/20 | ||

2 | 2 | 2/3/20 | 9/30/20 |

Any help much appreciated!

Sarah

]]>