This is confusing and difficut, but I hope it makes a sence.
I am interested in kind of like Random variable of Random variable.
This issue might've been mentioned below before.


[The Probability distribution of Random variable of Random variable](https://mathoverflow.net/questions/107364/the-probability-distribution-of-random-variable-of-random-variable)


Let me clarify.  

Random variable of Random variable (RVoRV) here is **not**  

add/subtract operation of two random variables.  

It is about a single measurement of random variables, where each variable actually came from another random variable.  

or I should say, list of values for a distribution , where each value comes from its own parent-distribution. but measurement was done only once  



Is there any material or anything that mentioned this issue?


As an example,
I made matlab code below.  

It creates N different gaussian distributions with their N standard deviations chosen uniform randomly with some variance.
Then it draw a single value from each of N different gaussians as random variable, making a list of N values.  

now what is the standard deviation of this N value list?  

As i run this code over and over, sd stays near a certain value.
Any equation for that?  

Thank you.  
  
--------------------------  



clear all;
close all;
clc;


N=100000;% number of gaussian distributions


% mean for N gaussians -------------  

%gauss\_list\_mean=**rand**(1,N).\*20+10;%average  

gauss\_list\_mean=repmat(0,1,N);%average same value


% sigma for N gaussians -------------  

gauss\_list\_sd=**rand**(1,N).\*20;%standard deviation  

%gauss\_list\_sd=repmat(15,1,N);%standard deviation same value


%-----------------------------------------------------------------  

% draw a value from each of N different gaussian distributions  

%-----------------------------------------------------------------  

if 0% fast version  

 list\_drawn\_value=**randn**(1,N).\*gauss\_list\_sd+gauss\_list\_mean;  

else% slow  

  list\_drawn\_value=zeros(1,N);  

  for i=1:N  

   list\_drawn\_value(i) = normrnd(gauss\_list\_mean(i),gauss\_list\_sd(i));  
 end  

end


sd\_value=std(list\_drawn\_value);%Get standard deviation of values from N different gaussians


fprintf(' sd of drawn values from %d Gaussians =%g \n',N,sd\_value);


fprintf('mean(gauss\_list\_sd)=%g std(gauss\_list\_sd)=%g\n',mean(gauss\_list\_sd),std(gauss\_list\_sd));



Random variable of random variable
Your question will surely be closed, because it's not on topic for this site.


Nevertheless ... notice that the (pseudo-)random samples created by your code, say $X\_1,...,X\_N$, are such that each $X\_i = \mu\_i + \sigma\_i Z\_i$, where $\mu\_i = 10 + 20\,U\_i$ and $\sigma\_i = 20\,U\_i'$, with $Z\_i\sim \text{Gaussian}(0,1)$, and $U\_i,U\_i'\sim \text{Uniform(0,1)}$, and all are mutually independent. 


Thus, the $X\_i$ are i.i.d. with $X\_i = 10 + 20\,U\_i + 20\,U\_i'\,Z\_i$, and their sample variance is therefore a consistent estimator of $V(X\_i)= 20^2V(U\_i) + 20^2\,V(U\_i'\,Z\_i)$. 


Now $V(U\_i)=\frac{1}{12}$ and $V(U\_i'\,Z\_i)=E({U\_i'}^2\,Z\_i^2)-[E(U\_i'\,Z\_i)]^2 = E({U\_i'}^2)\,E(Z\_i^2)=\frac{1}{3}\cdot1$, so you should be seeing a sample standard deviation near $20\sqrt{\frac{5}{12}}$ (if I haven't made any arithmetic errors).


